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
static constant as Array size #70
Comments
The compiler treats static constants as "variables". Since, it is considered to be a variable instead of a constant, you are getting that error. Static constants are declared as variables. non-static constants are declared as constants. findconst does not consider static constants as constants which is causing the problem. |
Thanks to @VVWVV's work, starting from release 3.10.2 it's possible to use static enumerations to define constants with a scope limited to a single file. static enum { ARRAY_SIZE = 20 };
new a[ARRAY_SIZE]; @Southclaws, you probably want to close this. |
@Southclaws @Daniel-Cortez In my opinion, the issue is still not resolved. As As a matter of fact, we still can't create local static constants. Using a static enum would pollute the global namespace of the file when you just want the constant to remain visible just within a function or a block. |
Ah I misread the post from Daniel and thought |
@YashasSamaga, so how do you imagine "fixing" this? Treat all identifiers defined with |
If |
@Daniel-Cortez Hmm, I get your point. I think my own code will get screwed if Why not simply use the value of the EDIT: I see. The fix is pretty complicated: will have to make a new entry or use an existing entry in the symbol structure to store the initialization value for local static constants. |
If the fix is complicated, is this really worth the work? Symbolising constants with #define is good enough, right? |
Not sure if there is a better solution but the solution I mentioned is awfully bad as it involves adding a new member to the |
Also it would be pretty strange to the same identifier acting as both a variable and a compile-time constant at the same time, IMHO. |
@Southclaws Well you would have to use #undef at the end of the file to simulate static. But in a way, yes. You can use the enum trick now, as was mentioned before. Fixing this at this point would just allow for slightly nicer code and would make constants more consistent. It is up to you to decide, whether making constants behave consistently (currently, const behaves differently from static const, which it probably should not) is worth the effort or not. I mostly wanted this fixed, because static enums were not a thing back then. |
Global |
strings with just If we make |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I know this issue is kind of old, but since it's still not fully resolved, what if we introduce a |
This issue has been automatically marked as stale because it has not had recent activity. |
const Size = 5;
new data[Size]; // Works fine
static const Size = 5;
new data[Size]; // error 008: must be a constant expression; assumed zero
The text was updated successfully, but these errors were encountered: