0

I have version.c file with following line:

const uint8_t ID_SoftwareId[]   = { 'A', 'B', '0', '1', '0', '\0'};

I want to pass the A and B into this file through a definition. I tired few thigs but I usually end up with Too many initializers warning from gcc.

Any ideas?

Community
  • 1
  • 1
devemouse
  • 5,302
  • 5
  • 22
  • 22

2 Answers2

0

Have you tried simply:

const uint8_t ID_SoftwareId[]   = { DEFA, 'B', '0', '1', '0', '\0'};

Then:

gcc -DDEFA=\'A\' ...

WorksForMeTM.

Mat
  • 202,337
  • 40
  • 393
  • 406
0

Proof of concept:

#define TOKENIZE(x) #x
#define SINGLECHAR(x) (*(TOKENIZE(x)))

int main()
{
    char c = SINGLECHAR(DEFINITION);
    return 0;
}

Compiled and run:

cpp -DDEFINTION=Q test.c

Output

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"



int main()
{
 char c = (*("Q"));
 return 0;
}
sehe
  • 374,641
  • 47
  • 450
  • 633