Update # 2: test results with gcc 4.7.0
This is really fixed in gcc 4.7.0. Your code produces the following assembler output:
.file "constexpr.cpp" .globl _ffx .section .rdata,"dr" .align 4 _ffx: .long 1
what you probably want. Update?
I think for this you will need a specific solution for the platform. See Searching for code and data in memory (Scatterloading) :
Scatterloading allows you to split the application into several separate areas of code and data distributed throughout the address map. The location of these regions may vary between load time and runtime:
- Download regions contain application code and / or data used by the application during on / off (usually ROM).
Instead of relying solely on gcc, try using armlink
, as suggested in the link above.
Update: I saw the gcc error you noted. LLVM / MinGW is also hopeless. However, I played with GCC 4.6, and here I think it might help you:
struct Data { int i; }; constexpr Data getData() { return Data{1}; }
If instead of having ctor you have a constexpr
function and try to generate assembler output, the output will usually be empty (no .data
). And if you use this to initialize some variable (in the global scope), as shown below:
const Data foo = getData();
You will get the assembly as follows:
.file "constexpr.cpp" .section .rdata,"dr" .align 4 __ZL3foo: .long 1
(this is with the command line g++ -std=c++0x -S
). Does this work for you?