This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Initializing a const code structure with __DATE__

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

Parents
  • 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?

Reply
  • 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?

Children