AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=58)
-   -   SourcePawn compiler suggestion (https://forums.alliedmods.net/showthread.php?t=330565)

Gold Fish 02-10-2021 13:09

SourcePawn compiler suggestion
 
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.

Psyk0tik 02-11-2021 03:57

Re: SourcePawn compiler suggestion
 
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.

Gold Fish 02-11-2021 04:15

Re: SourcePawn compiler suggestion
 
Quote:

Originally Posted by Crasher_3637 (Post 2736467)
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
https://funkyimg.com/p/3aH77.jpg

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
!

https://funkyimg.com/i/3aH7M.jpg

DJ Tsunami 02-11-2021 06:26

Re: SourcePawn compiler suggestion
 
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.

Gold Fish 02-11-2021 07:01

Re: SourcePawn compiler suggestion
 
Quote:

Originally Posted by DJ Tsunami (Post 2736477)
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 02-11-2021 07:03

Re: SourcePawn compiler suggestion
 
Quote:

Originally Posted by DJ Tsunami (Post 2736477)
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!

helloworlds 11-08-2022 04:55

Re: SourcePawn compiler suggestion
 
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 (Post 2736467)
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.

Marttt 11-08-2022 19:48

Re: SourcePawn compiler suggestion
 
Quote:

Originally Posted by Psyk0tik (Post 2736467)
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.



All times are GMT -4. The time now is 05:56.

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