GNOME Bugzilla – Bug 530623
Support local constants
Last modified: 2010-10-13 20:19:13 UTC
We should add support for local constants, i.e. constants within methods. We should probably support more inner declarations in methods in general, e.g. inner methods.
*** Bug 541152 has been marked as a duplicate of this bug. ***
*** Bug 589603 has been marked as a duplicate of this bug. ***
*** Bug 601341 has been marked as a duplicate of this bug. ***
Here's a simple test case. int main() { const int foo = 33; return foo; } We should provide at least a helpful error message insteaf of 'syntax error, expected ';'' If they are local they can be replaced inline in code or just use 'const' attribute in C code generation. It should be the same effect at compile time.
inner function with outer scope? :)
I think local constants should be expanded instead of #define This will fix many issues related to constants named as keywords or function names which results in even weirdest errors.
Another solution would be to just #define and #undef at the end of the function. int class_method_function() { #define CLASS_METHOD_CONSTNAME value ... #undef CLASS_METHOD_CONSTNAME }
commit 46fece1d814e59bb1443697fda41132a93bc4978 Author: Jürg Billeter <j@bitron.ch> Date: Wed Oct 13 22:17:41 2010 +0200 Add suport for local constants Fixes bug 530623.