compile-time-constant

Are all compile-time constants inlined?

早过忘川 提交于 2019-11-27 01:21:10
Let's say I have a class like this: class ApplicationDefs{ public static final String configOption1 = "some option"; public static final String configOption2 = "some other option"; public static final String configOption3 = "yet another option"; } Many of the other classes in my application are using these options. Now, I want to change one of the options alone and deploy just the compiled class. But if these fields are in-lined in the consumer classes this becomes impossible right? Is there any option to disable the in-lining of compile time constants? reccles You can use String.intern() to

Why doesn't a Java constant divided by zero produce compile time error? [duplicate]

时光毁灭记忆、已成空白 提交于 2019-11-26 20:57:19
问题 Possible Duplicate: Is 1/0 a legal Java expression? Why does this code compile? class Compiles { public final static int A = 7/0; public final static int B = 10*3; public static void main(String[] args) {} } If I take a look in the compiled class file, I can see that B has been evaluated to 30, and that A still is 7/0. As far as I understand the JSL an expression where you divide by zero is not a constant. Ref: JLS 15.28 My above statement is due to this line: A compile-time constant

constexpr overloading

心已入冬 提交于 2019-11-26 17:31:16
Related: Function returning constexpr does not compile I feel like constexpr is limited in usefulness in C++11 because of the inability to define two functions that would otherwise have the same signature, but have one be constexpr and the other not constexpr. In other words, it would be very helpful if I could have, for example, a constexpr std::string constructor that takes constexpr arguments only, and a non-constexpr std::string constructor for non-constexpr arguments. Another example would be a theoretically complicated function that could be made more efficient by using state. You can't

Compile-time constants and variables

左心房为你撑大大i 提交于 2019-11-26 15:51:10
The Java language documentation says: If a primitive type or a string is defined as a constant and the value is known at compile time, the compiler replaces the constant name everywhere in the code with its value. This is called a compile-time constant. My understanding is if we have a piece of code: private final int x = 10; Then, the compiler will replace every occurrence of x in the code with literal 10 . But suppose the constant is initialized at run-time: private final int x = getX(); // here getX() returns an integer value at run-time. Will there be any performance drop (howsoever

Are all compile-time constants inlined?

感情迁移 提交于 2019-11-26 09:37:18
问题 Let\'s say I have a class like this: class ApplicationDefs{ public static final String configOption1 = \"some option\"; public static final String configOption2 = \"some other option\"; public static final String configOption3 = \"yet another option\"; } Many of the other classes in my application are using these options. Now, I want to change one of the options alone and deploy just the compiled class. But if these fields are in-lined in the consumer classes this becomes impossible right? Is

Compile-time constants and variables

南笙酒味 提交于 2019-11-26 04:11:23
问题 The Java language documentation says: If a primitive type or a string is defined as a constant and the value is known at compile time, the compiler replaces the constant name everywhere in the code with its value. This is called a compile-time constant. My understanding is if we have a piece of code: private final int x = 10; Then, the compiler will replace every occurrence of x in the code with literal 10 . But suppose the constant is initialized at run-time: private final int x = getX(); //

Java switch statement: Constant expression required, but it IS constant

元气小坏坏 提交于 2019-11-26 00:19:50
问题 So, I am working on this class that has a few static constants: public abstract class Foo { ... public static final int BAR; public static final int BAZ; public static final int BAM; ... } Then, I would like a way to get a relevant string based on the constant: public static String lookup(int constant) { switch (constant) { case Foo.BAR: return \"bar\"; case Foo.BAZ: return \"baz\"; case Foo.BAM: return \"bam\"; default: return \"unknown\"; } } However, when I compile, I get a constant

Does “int size = 10;” yield a constant expression?

白昼怎懂夜的黑 提交于 2019-11-25 23:43:36
问题 The following code compiles under gcc 4.8 and Clang 3.2: int main() { int size = 10; int arr[size]; } 8.3.4/1 of the C++ Standard says that the size of an array must be an integral constant expression, which size does not seem to be. Is this a bug in both compilers, or am I missing something? The latest VC++ CTP rejects the code with this interesting message: error C2466: cannot allocate an array of constant size 0 The interesting part is how it seems to think that size is zero. But at least