Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Is enum a suitable way to implement a "local define?"
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="David Thompson" data-source="post: 5161602"><p>On Thu, 10 Apr 2014 19:36:53 +0000 (UTC), glen herrmannsfeldt</p><p></p><p></p><p>If primitive type or String and initialized by a constant expression,</p><p>the compiler can AND MUST fold it. See definition of 'constant</p><p>variable' (!) in 4.12.4, and 13.1p3 and 13.4.9, in Java 7 Language</p><p>Specification; I ass-u-me 8 is the same but haven't looked yet.</p><p></p><p>In particular 13.4.9 says this should be used for "only values which</p><p>truly are unlikely ever to change" and 13.4.10 shows a kludgy way to</p><p>make the initialization of an actual constant value a non-constant</p><p>expression and thus the variable not foldable.</p><p></p><p>This is similar to C++'s making a namespace-scope const integer object</p><p>initialized by constant expression into a constant itself. C++ doesn't</p><p>require this for floating-point on the theory that runtime (target)</p><p>floating-point may differ from the compiler. Java tried to require</p><p>IEEE floating-point everywhere but had to back off.</p><p></p><p>In order to resolve overloads and check types the java compiler</p><p>already requires that all classes and interfaces referenced from and</p><p>not defined in the set of source files processed in one compilation --</p><p>what I might loosely call 'net imports' -- must be available already</p><p>compiled in CLASSPATH, usually though not necessarily in library jars.</p><p>This means the needed 'static final' values are available.</p></blockquote><p></p>
[QUOTE="David Thompson, post: 5161602"] On Thu, 10 Apr 2014 19:36:53 +0000 (UTC), glen herrmannsfeldt If primitive type or String and initialized by a constant expression, the compiler can AND MUST fold it. See definition of 'constant variable' (!) in 4.12.4, and 13.1p3 and 13.4.9, in Java 7 Language Specification; I ass-u-me 8 is the same but haven't looked yet. In particular 13.4.9 says this should be used for "only values which truly are unlikely ever to change" and 13.4.10 shows a kludgy way to make the initialization of an actual constant value a non-constant expression and thus the variable not foldable. This is similar to C++'s making a namespace-scope const integer object initialized by constant expression into a constant itself. C++ doesn't require this for floating-point on the theory that runtime (target) floating-point may differ from the compiler. Java tried to require IEEE floating-point everywhere but had to back off. In order to resolve overloads and check types the java compiler already requires that all classes and interfaces referenced from and not defined in the set of source files processed in one compilation -- what I might loosely call 'net imports' -- must be available already compiled in CLASSPATH, usually though not necessarily in library jars. This means the needed 'static final' values are available. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Is enum a suitable way to implement a "local define?"
Top