Would be very useful in my current PB project.
Static keyword behaviour that mimics C
Static keyword behaviour that mimics C
Can i make a request for the static keyword to be overloaded to create global variables with source file scope like C?
Would be very useful in my current PB project.
Would be very useful in my current PB project.
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
Re: Static keyword behaviour that mimics C
It's a good idea I totally do not understand a word you're saying 
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
- Fluid Byte
- Addict

- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: Static keyword behaviour that mimics C
Show us how that would look like in C and I'm sure someone can answer that question.Blood wrote:Can i make a request for the static keyword to be overloaded to create global variables with source file scope like C?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Re: Static keyword behaviour that mimics C
In C the static keyword serves two purposes. Firstly the one we know from Purebasic inside
Procedures, and secondly, when used on global variables outside any procedure the 'static'
means that only the functions within the same sourcefile have access to it. This even
works for functions themselves, e.g. a function declared like this:
can only be used within the sourcefile it exists.
That's a very useful 'scope-limiting' feature!
Procedures, and secondly, when used on global variables outside any procedure the 'static'
means that only the functions within the same sourcefile have access to it. This even
works for functions themselves, e.g. a function declared like this:
Code: Select all
static void foo();That's a very useful 'scope-limiting' feature!
Windows 7 & PureBasic 4.4
Re: Static keyword behaviour that mimics C
Thats one thing I dislike in PB, all the includes share the same namespace. I always have to give all global variables prefixes in all includes so that nothing is overlapping. I never programmed in C, but it sounds very useful.
pb 5.11
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Static keyword behaviour that mimics C
that is a good idea!
according to PureBasic's conventions, it would mean to declare a Variable Protected outside a Procedure.
according to PureBasic's conventions, it would mean to declare a Variable Protected outside a Procedure.
oh... and have a nice day.
Re: Static keyword behaviour that mimics C
Yes! It would provide a simple namespace for source files. For example, you could define lots of global variables in one source file that work with particular procedures in that source file. When this source file is included into another, that file cannot see the static globals in the included one. Also for procedures, you could create ones that are hidden from other source files, etc.. Very useful IMHO.milan1612 wrote:In C the static keyword serves two purposes. Firstly the one we know from Purebasic inside
Procedures, and secondly, when used on global variables outside any procedure the 'static'
means that only the functions within the same sourcefile have access to it. This even
works for functions themselves, e.g. a function declared like this:can only be used within the sourcefile it exists.Code: Select all
static void foo();
That's a very useful 'scope-limiting' feature!
At the minute everything is lumped together.
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
Re: Static keyword behaviour that mimics C
I can't agree more to this! Actually, the idea to mimic C in this case is a very good one, becauseBlood wrote:At the minute everything is lumped together.
this doesn't break existing code as inside procedures the meaning of static wouldn't change.
Fred, what do you say?
Windows 7 & PureBasic 4.4
Re: Static keyword behaviour that mimics C
Ah so.
Well, I'd like 'modules' or 'workspaces' better, I think this discussion took place once before...
I'd rather prefer something like this:
Now all that would remain is a syntax that would not interfere too much with the old behaviour... We've got...
Perhaps a level more could help? Perhaps 'Universal' or 'Beyond'...
An alternative would be workspace adressing, perhaps in combination with the above, but the syntax might be tricky...
It's all just a suggestion...
Well, I'd like 'modules' or 'workspaces' better, I think this discussion took place once before...
I'd rather prefer something like this:
Code: Select all
Workspace apple
;
a.f = 1
;
Workspace pear
;
a.f = 1
;
Code: Select all
Local a.f
Global b.f
Code: Select all
Local a.f
Global b.f
Universal c.f
Beyond d.f
Code: Select all
Workspace apple
;
Beyond a.f = 1
Global b.f = 2
;
Workspace pear
;
a.f = 3 ; would affect a.f in all workspaces
Global b.f = 4
;
Debug a.f ; returns 3
Debug apple:b.f ; returns 3
Debug b.f ; returns 4
Debug pear:b.f ; returns 4
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Static keyword behaviour that mimics C
Yupblueznl wrote: Well, I'd like 'modules' or 'workspaces' better, I think this discussion took place once before...
http://www.purebasic.fr/english/viewtop ... 486#p98486
"Have you tried turning it off and on again ?"
Re: Static keyword behaviour that mimics C
Any news on this request? It has, after all, been nearly two years.
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
- RichAlgeni
- Addict

- Posts: 935
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: Static keyword behaviour that mimics C
Does this mean that included source files would not 'see' the same value of the variables that the main line source would see? Or that variable would be separate for included source?secondly, when used on global variables outside any procedure the 'static' means that only the functions within the same source file have access to it.
Would this be for the purpose of security?

