Raised This Month: $12 Target: $400
 3% 

SourcePawn compiler suggestion


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gold Fish
Senior Member
Join Date: Mar 2020
Old 02-10-2021 , 13:09   SourcePawn compiler suggestion
Reply With Quote #1

Pawn compiler has a preprocessor directive #pragma warning disable <number>,
For example #pragma warning disable 203
which removes warnings, please add this directive to the sourcepawn compiler.

It is very uncomfortable to compile the code, there are a lot of warning 213: tag mismatch warnings, they clog the compiler log.
Thanks.

Last edited by Gold Fish; 02-10-2021 at 13:10.
Gold Fish is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 02-11-2021 , 03:57   Re: SourcePawn compiler suggestion
Reply With Quote #2

Instead of asking for a feature to disable warnings (which are helpful for maintaining your code), why not actually fix the code to get rid of the warnings instead? Tag mismatches are easy to fix.
__________________
Psyk0tik is offline
Gold Fish
Senior Member
Join Date: Mar 2020
Old 02-11-2021 , 04:15   Re: SourcePawn compiler suggestion
Reply With Quote #3

Quote:
Originally Posted by Crasher_3637 View Post
Instead of asking for a feature to disable warnings (which are helpful for maintaining your code), why not actually fix the code to get rid of the warnings instead? Tag mismatches are easy to fix.
OK


PHP Code:
plugin.sp(11) : warning 213tag mismatch
plugin
.sp(11) : warning 213tag mismatch
plugin
.sp(11) : warning 213tag mismatch
plugin
.sp(12) : warning 213tag mismatch
plugin
.sp(12) : warning 213tag mismatch
plugin
.sp(12) : warning 213tag mismatch
plugin
.sp(13) : warning 213tag mismatch
plugin
.sp(13) : warning 213tag mismatch
plugin
.sp(13) : warning 213tag mismatch

Code size
:             3248 bytes
Data size
:             2876 bytes
Stack
/heap size:      16384 bytes
Total requirements
:   22508 bytes
9 Warnings

Here is a simple and neat code, what should I fix here ??

9 useless warnings that get in the way
!


Last edited by Gold Fish; 02-11-2021 at 04:19.
Gold Fish is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 02-11-2021 , 06:26   Re: SourcePawn compiler suggestion
Reply With Quote #4

You are storing strings in an integer array. So those warnings are not so useless after all.

To use different variable types in an array probably want to use enum structs.

Also, spcomp already has -w<num> to disable a specific warning by its number.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 02-11-2021 at 06:30.
DJ Tsunami is offline
Gold Fish
Senior Member
Join Date: Mar 2020
Old 02-11-2021 , 07:01   Re: SourcePawn compiler suggestion
Reply With Quote #5

Quote:
Originally Posted by DJ Tsunami View Post
You are storing strings in an integer array. So those warnings are not so useless after all.

To use different variable types in an array probably want to use enum structs.

Also, spcomp already has -w<num> to disable a specific warning by its number.
Thanks a lot, didn't know about this.
But it would be more convenient with the preprocessor directive #pragma so that the online compiler would also support this function
Gold Fish is offline
Gold Fish
Senior Member
Join Date: Mar 2020
Old 02-11-2021 , 07:03   Re: SourcePawn compiler suggestion
Reply With Quote #6

Quote:
Originally Posted by DJ Tsunami View Post
You are storing strings in an integer array. So those warnings are not so useless after all.
To use different variable types in an array probably want to use enum structs.
As it turned out, the strings are perfectly stored in such a static array together with numbers, no compilation errors, not after. and even don't crashes, maybe I'm wrong, but I found a very convenient way for myself to combine many arrays (structures) into one static array (read-only strings)

You just have no idea how convenient it is to go quickly in one loop through the entire multi-level array!

Last edited by Gold Fish; 02-11-2021 at 07:07.
Gold Fish is offline
helloworlds
Junior Member
Join Date: Oct 2022
Old 11-08-2022 , 04:55   Re: SourcePawn compiler suggestion
Reply With Quote #7

Edit: answering my own question: there's a <testing> include in SourceMod I was completely unaware of that solves this.

PHP Code:
AssertEq("Array size mismatch"sizeof(foo), sizeof(bar)); 
___________

Quote:
Originally Posted by Psyk0tik View Post
Instead of asking for a feature to disable warnings (which are helpful for maintaining your code), why not actually fix the code to get rid of the warnings instead?
Ok.

PHP Code:
#include <sourcemod>

#define DEBUG true

char foo[123];
char bar[123];

public 
void CopyFooBar()
{
#if DEBUG
    // Checking for programmer error in DEBUG,
    // because these sizes *must* equal to avoid a truncated strcopy,
    // which would not trigger a compiler error but
    // silently introduce unintended behaviour at runtime.
    
if (sizeof(foo) != sizeof(bar)) // suppress-warning: 205: redundant code... if only
    
{
        
SetFailState("Array size mismatch");
    }
#endif
    
strcopy(foosizeof(foo), bar);

How would you fix this? I would rather not write warning comments near the stack allocations fingers crossed that the programmer read them, but rather have the program fail loudly.

In SourceMod pre-1.11, you could write
PHP Code:
#if sizeof(foo) != sizeof(bar)
#error You're doing it wrong!
#endif 
to manually fail the compile, but this behaviour has been sadly disabled in SM 1.11.

Last edited by helloworlds; 11-08-2022 at 05:12. Reason: solved
helloworlds is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-08-2022 , 19:48   Re: SourcePawn compiler suggestion
Reply With Quote #8

Quote:
Originally Posted by Psyk0tik View Post
Instead of asking for a feature to disable warnings (which are helpful for maintaining your code), why not actually fix the code to get rid of the warnings instead? Tag mismatches are easy to fix.
__________________
Marttt is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode