Errors, bugs, questions - page 2860
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Is this correct compiler behavior? It seems that A::i is not created at the moment of calling the A::f() method calling A::i.
What is meant by "created" ?
static is just a way to create a rake to hide a global variable or function, limiting the visibility of a function or class
The memory for a global variable always exists.
And yes, for global variables the initialization order is very important (I mean, avoid accessing the variable before it is initialized)
This example worked...
In the example above it worked...
Are you going to change the compiler at this point? Personally, I'd like to keep it the way it is.
Will you change the compiler at this point? Personally, I'd like to keep everything as it is.
We are not planning to change the behaviour.
But there is a deferred task of detecting errors of access to global variables (before initialization).
If we implement this feature, we'll get a warning when compiling the above code: the A::f() function is used to initialize A::i, which accesses the A::i variable being initialized.
If we implement the feature, you will get a warning message when compiling the above code: the A::f() function is used to initialize A::i, which accesses the A::i variable being initialized.
Thank you!
We do not plan to change the behaviour
Then it contradicts your concept that a variable is considered declared when the declaration is complete. Why did you invent it in the first place? If it's like that in one case and different in another case
A good language has uniform rules, not the other way roundThen it contradicts your own concept that a variable is considered declared when the declaration is complete. Why did you invent it in the first place? If it is so in one case and different in another
A good language has uniform rules, not the other way roundI'm a total ignoramus, but I wouldn't have thought of it (int i = i) even if I had drunk too much....... 8(
I'm a total ignoramus, but I wouldn't have thought of this (int i = i) even if I had drunk too much....... 8(
And what is the principal difference from the original example? Remove unnecessary things and you'll get it:
Only there are a lot of strings there, and only one here.
If there is no compilation error there shouldn't be one here too (and vice versa), otherwise it's a mess
Then it contradicts your own concept that a variable is considered declared when the declaration is complete. Why did you invent it in the first place? If it is so in one case and different in another
A good language has uniform rules, not the other way aroundWhat is the fundamental difference from the original example? Take away the extra stuff and you've got it:
Only there are a lot of lines there, and only one here
If there's no compilation error there shouldn't be one here too (and vice versa), otherwise it's a mess.
You're wrong, it's not the same thing.
Description of a static variable in a class is its pre-definition (similar to pre-definition of a function or class), but location, in fact, just tells the compiler where the variable will be stored in memory and when it should be initialized