compile-time-constant

Are all compile-time constants inlined?

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 chan...

initialize a variable statically (at compile time)

Hi guys, 1) I've got many constants in my C algo. 2) my code works both in floating-point and fixed-point. Right now, these constants are initialized by a function, float2fixed, whereby in floating-point it does nothing, while in fixed-point, it finds their fixed-point representation. For instance, 0.5f stays 0.5f if working in floatin...

Can I compute pow(10,x) at compile-time in c?

Is it possible to compute pow(10,x) at compile time? I've got a processor without floating point support and slow integer division. I'm trying to perform as many calculations as possible at compile time. I can dramatically speed up one particular function if I pass both x and C/pow(10,x) as arguments (x and C are always constant in...

How to give dynamically created buttons actions for each one - part 2

Hi again fellow Flashers :) My first question poised here at StackOverFlow dealt with this issue, I had an array which created a few different buttons. However I didn't know how to assign actions to them: How to give dynamically created buttons actions for each one - part 1 Thanks to Joel Hooks, I was able to get my code working. Howev...

Help with type traits

Suppose we have the following template class template<typename T> class Wrap { /* ... */ }; We can not change Wrap. It is important. Let there are classes derived from Wrap<T>. For example, class NewInt : public Wrap<int> { /* ... */ }; class MyClass : public Wrap<myclass> { /* ... */ }; class Foo : public Wrap<Bar> { /...

Time consts in Java?

Is there a Java package with all the annoying time consts , like miliseconds/seconds/minutes in a minute / hour /day / year ? I'd hate to duplicate something like that ...

Different behavior of compilers with array allocation

I recently found a interesting behaviour of g++ when compared with MSVC++ 2008. Consider this tiny program: #include <cstdlib> const int ARR_LENGTH = 512; void doSomething( int iLen ); int main( int argc, char** argv ) { doSomething( ARR_LENGTH ); return 0; } void doSomething( int iLen ) { int iTest[iLen]; return; } ...

Why is −1 > sizeof(int)?

Consider the following code: template<bool> class StaticAssert; template<> class StaticAssert<true> {}; StaticAssert< (-1 < sizeof(int)) > xyz1; // Compile error StaticAssert< (-1 > sizeof(int)) > xyz2; // OK Why is -1 > sizeof(int) true? Is it true that -1 is promoted to unsigned(-1) and then unsigned(-1) > sizeof(int). Is it true ...

C++ compile-time constant detection

Tbere're cases when a library source is available, and it has to support variable parameters in general, but in practice these parameters are commonly constants. Then it may be possible to optimize things by special handling of constant parameters (eg. use static arrays instead of heap allocation), but for that its necessary to determin...

[AS3] Get compile-time variable at runtime

I am trying to use the "define" mxmlc compiler option to embed compile-time constants into my SWF files. <mxmlc ...> <define name="NAMES::PluginCompileTime" value="Hello World!"/> </mxmlc> I can access this variable if I "hardcode" it into my codebase, as so: public static const PLUGIN_COMPILED_TIME:String = NAMES::PluginCompile...

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

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) { switc...

How to efficiently implement an immutable graph of heterogenous immutable objects in C++?

I am writing a programming language text parser, out of curiosity. Say i want to define an immutable (at runtime) graph of tokens as vertices/nodes. These are naturally of different type - some tokens are keywords, some are identifiers, etc. However they all share the common trait where each token in the graph points to another. This pro...