Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning on unused public variables. #71

Closed
Y-Less opened this issue Jun 19, 2015 · 5 comments
Closed

Warning on unused public variables. #71

Y-Less opened this issue Jun 19, 2015 · 5 comments

Comments

@Y-Less
Copy link
Member

Y-Less commented Jun 19, 2015

I don't know if this is fixed as I don't have a compiler installed to test it on (sorry), but I do remember encountering it a few times in the past. Unused public functions don't have warnings because they may be used in reality by the VM (or by code modification), the same logic should apply to public variables. Currently they get a warning if they are unused, but I've had situations where I wanted them remaining. I know there is #pragma unused, but that's not ideal (especially in macros). An alternate solution would be to make stock public not an invalid combination (in fact that might be the best solution for compatibility and explicitness).

@Y-Less
Copy link
Member Author

Y-Less commented Jun 20, 2015

It has just occurred to me that they can already be both public and stock (and by "occurred to me" I mean "I read that in the comments around your latest commit"). In that case, an unused stock public is removed without warnings. So I think that it should revert to never warning, but also not always removing if the variable is public, since it is already clearly special by virtue of the fact that it is public and so possibly expected by the VM.

@Zeex Zeex closed this as completed in d8f8243 Jun 20, 2015
@Zeex
Copy link
Contributor

Zeex commented Jun 20, 2015

Now the compiler won't remove public variables, even unused ones (It will still warn though if they are not marked as stock).

@Y-Less
Copy link
Member Author

Y-Less commented Jun 20, 2015

I didn't actually realise it did remove unused non-stock ones. So this way does seem like the best solution thanks.

@Zeex
Copy link
Contributor

Zeex commented Jun 21, 2015

Public variables seem like a great thing, it's interesting how SA-MP doesn't use them anywhere. Could be a good candidate for things like MAX_PLAYERS and such, especially now that they added this GetPlayerPoolSize() function. Much faster than calling a native anyway...

@Y-Less
Copy link
Member Author

Y-Less commented Jun 22, 2015

// Consume leading spaces.
#define @yN_%0\32%1 @yN_%0%1

// Consume other declarations ("final public x" etc).
//#define @yN_const%0\32%1 @yN_%0%1
#define @yN_static%0\32%1 @yN_%0%1
#define @yN_stock%0\32%1 @yN_%0%1
#define @yN_public%0\32%1 @yN_%0%1

#define final%0= %0;@yN_%0();@yN_%0()%0=

public final cMaxPlayers = GetPlayerPoolSize();

Code to call all @yN_ functions on startup is trivial (at least with YSI and amx_assembly):

hook OnScriptInit()
{
    new
        idx,
        buffer;
    while ((idx = AMX_GetPublicPointerPrefix(idx, buffer, _A<@yN_>)))
    {
        CallFunction(buffer);
        // Or (faster but harder):
        //#emit PUSH.C     0
        //#emit LCTRL      6
        //#emit ADD.C      28
        //#emit PUSH.pri
        //#emit LOAD.S.pri buffer
        //#emit SCTRL      6
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants