Raised This Month: $ Target: $400
 0% 

declaring static as global crashes the server if used in a function outside the file?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-04-2021 , 07:16   Re: declaring static as global crashes the server if used in a function outside the f
Reply With Quote #4

No. Symbol (variable name, etc) scope has an effect only on where you can name it from. Think about local variables:
Code:
someFunction() {
    const x = 5;
    print_server("%d", x);
}
x in this case is pointing to some value in memory and is scoped to this function, i.e. you can't use it ("name" it) from outside someFunction. Yet, you can send its value to AMXX, other plugins etc through natives. Same goes for global static variables, but their scope is the file they are defined in, not some function. File scoping is useful for include files, where you need some global data but don't want to expose it to plugins that include it, or for large plugins that are split into multiple files.
__________________

Last edited by klippy; 04-04-2021 at 07:19.
klippy is offline
 


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 17:38.


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