Bug 4163 - Pragma unused and arrays
Pragma unused and arrays
Status: RESOLVED WONTFIX
Product: AMX Mod X
Classification: Unclassified
Component: Core
trunk
PC All
: P3 trivial
Assigned To: amxmodx-bugs@alliedmods.net
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-12-23 16:49 PST by Lt.RAT
Modified: 2013-07-04 13:08 PDT (History)
3 users (show)

See Also:


Attachments

Description Lt.RAT 2009-12-23 16:49:51 PST
With #pragma unused possible to create 0 bound arrays

Code:
arr[-1]
#pragma unused arr
generates an error: invalid array size (negative or zero)

but code:
arr[0]
#pragma unused arr
no error :(

also it registers in debug section of the file (amxxdump failed to read and analyze it)


P.S. Maybe: 
1) remove from debug section symbols (with zero using)
2) also possible to do arr[1][], but it really useless... maybe restrict 1 bound arrays, or optimize :)
Comment 1 David Anderson [:dvander] 2009-12-23 17:24:44 PST
IMO #pragma unused should not exist.
Comment 2 Lt.RAT 2009-12-24 04:13:05 PST
It useful to suppress warnings on debug temporary variables.
Comment 3 David Anderson [:dvander] 2009-12-24 04:16:42 PST
That doesn't sound too useful. Either the variables shouldn't be there, or the warning should be entirely optional, pref'd off by default.
Comment 4 Lt.RAT 2009-12-24 04:58:28 PST
But that warning useful if we write smth like:

stock kz_show_hud(id, r, g, b, Float:x, Float:y, const msg[])
{
	if(is_user_connected(id))
	{
		set_hudmessage(r, g, b, -1.0, y, 0, 0.0, 3.0, 0.0, 0.0, 4);
		//etc without using of x
	}
}

Then it`ll say that x never used, so we can simplify function, and without warning we can miss such things... It should not be off by default.

So, i think that #pragma unused has the right to live
Comment 5 David Anderson [:dvander] 2009-12-24 05:19:42 PST
I don't think that's a good use case. The compiler is being too aggressive. It is very common to have unused inparams in functions because the implementation can evolve to make them unnecessary, and compatibility has to be preserved. I don't think C/C++ compilers even warn about unused inparams by default anymore.

My beef here is twofold. First, it doesn't seem meaningful to have (buggy) preprocessor markup for an analysis that has little benefit. If the entire goal is to tell you that you have an unused parameter somewhere, it makes more sense to turn this functionality off by default, and allow users to pass a "--warn-unused" option or something, to opt-in to a specific pedantic warning.

Second, I don't like the fact that this is being done in the preprocessor - that's a gross hack. It seems more sensible to have an "unused" keyword/attribute that you affix to the parameter in the function declaration.
Comment 6 Lt.RAT 2009-12-24 06:36:19 PST
IMO it`s a great idea to have unused keyword/attribute (but not only in function declaration), this can fully replace pragma unused in more proper way...

But in both ways it shouldn`t have bug with arr[0] declaration :) 

New keyword would be better, but not so many people will use it, and it`s really small enhancement.
Comment 7 joropito 2013-07-04 13:08:31 PDT
I think all has said about this.

Note You need to log in before you can comment on or make changes to this bug.