This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I want to declare some constant data in a .cpp with the intent of locating it in a specifically-named section.
I find that I had to do this: (in "datatest.cpp")
// default section
extern const unsigned int abc[] = {3, 4, 5, 6};
#pragma DATA_SECTION("foo");
extern const char def[] = "To be or not to be... that is the question!";
#pragma DATA_SECTION("bar");
extern const unsigned int ghi[] = {1, 2, 3, 444, 555};
If I didn't have the "const", it would put data in .cinit; if I had the "const" but the "extern", it wouldn't show up in my output at all.
Are these variables defined correctly? What's the proper way to reference them in a .h file? Is it:
extern const unsigned int abc[];
or
extern const unsigned int *abc;
or do I have to know the array size?
extern const unsigned int abc[4];
By the format of your pragmas, I can tell you are compiling this in C++ mode. In C++, const globals are visible only in the current file, unless you explicitly use the "extern" keyword. If you do not use the "extern" keyword, and you do not refer to the array within this file, it will be excluded from the output. If you want to place the declaration in a header file: In the header file, use "extern const unsigned int abc[];" In one and only one source file, define it with "extern const unsigned int abc[] = { whatever };"