Jump to content

Static Keyword Ignored


Guest JoeB

Recommended Posts

Hi,

 

If a variable is declaired as static in a file (not in a function), the variable should only be in scope within that file, therefore allowing more than one variable with the same name to be declaired in different files.

 

The compiler (BoostC) appears to be ignoring the static keyword on file-global data members and forcing the declaired variable to be project global.

 

 

 

Example:

 

3 files; Test.c, Common.c, Common.h

 

---

 

Common.c:

#include "common.h"

:

static char aaa; // should be accessable within Common.c only

 

---

 

Test.c:

#include "common.h"

:

void main(void)

{

aaa = 0; // aaa is not in scope in Test.c. Can only be used in common.c

}

 

---

 

 

Correct me if im being dumb please -- after all, its Monday morning!

 

http://tigcc.ticalc.org/doc/keywords.html#static

 

J

Edited by JoeB
Link to post
Share on other sites
If a variable is declaired as static in a file (not in a function), the variable should only be in scope within that file, therefore allowing more than one variable with the same name to be declaired in different files.

...

Correct me if im being dumb please -- after all, its Monday morning!

 

Yes you are correct and if BoostC doesn't work this way it's a bug. It'll be great if you can send a (simple) sample project that demonstrates this issue to support@picant.com

 

Regards,

Pavel

Link to post
Share on other sites

I've figured it out. I was declaiing the variable as static in the header file, which means the compiler created a seperate instance of the variable each time the header file was included.

 

So not a compiler bug after all!

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...