Hi everyone,
I have the following working code:
typedef struct { int spam; int eggs; char padding[200]; } MyStruct; const char code foo[] = "This is a string."; const MyStruct code bar = { 1, 2 }; // padding not initialized
Because MyStruct includes padding that is currently unused, I would like to move the contents of foo into the structure. Within my application, this makes logical sense in addition to reducing the amount of wasted code space. I would like to do something like the following, but I can't get it to work:
typedef struct { int spam; int eggs; char foo[18]; // includes \0 at end char padding[182]; } MyStruct; const char code bar = { 1, 2, "This is a string." };
I am getting the error "non-address/constant initializer". Any suggestions?
-Scott
Sorry, I forgot to change subject title -- ignore the __DATE__ part; problem persists even with just a plain string.
const MyStruct code bar = { 1, 2, "This is a string." };
Sorry.. I also mistyped my broken example. I am of course using MyStruct instead of char for the initialization line, however the error persists.
How can you mistype so much? Don't you have CTRL-C and CTRL-V?
A) .. not particularly helpful .. B) These snippets are meant to be representative of the scenario I am trying to reproduce; I cannot share my actual code as it is protected by a controlled goods program.
You are either able to reproduce the problem with snippets. And then these snippets _are_ possible to post. Because the code would have been reduced to something so trivial that there can't be any tracde secret or licensing issues with posting it.
Or you can't reproduce, in which case you probably have some #define or other interesting concepts hidden somewhere that you haven't noticed yet. And then it would not be meaningful to post here, since we wouldn't know about that hidden code that you haven't even located yourself yet.
CTRL-C/CTRL-V is so infinitely more helpful than you may think. It's the only way we can know that we are seeing the real problem. Anything else is random hay hiding the needle.
Thanks for the help, Per; you may see from my original case that I am looking for suggestions as to what to look for, not for someone to fix my code.
Consider this thread closed; I will resolve the problem on my own. The sad part is that the resolution won't get logged for future users encountering similar (but not identical) problems with their own code.
Yes, but the name Scott Armitage will be logged for future users as someone who can't handle constructive critizism. Lots of other users have come to realize that the quality of the help is related to the quality of the original problem description.
In a very large percentage of cases, it is possible to create a real example that shows the problem, without containing any source code secrets, i.e. allowing the full code set to be posted. Have you tried?
Is the issue it won't compile, or doesn't get init.
This compiles for me?
typedef struct { int spam; int eggs; char foo[18]; // includes \0 at end char padding[182]; } MyStruct; const MyStruct bar = { 1, 2, "This is a string." };
I could not get this to compile using the 9.x series of the Keil tool chain. Programmatically we have since reverted to v8.12, under which the (unmodified) source compiles just fine. I did not investigate further.