I am using the library argp
in C and I wonder why the two following things are not equivalent:
Code 1:
const char * const doc = "Welcome to my program";
struct argp argp = { NULL, NULL, NULL, doc };
Code 2:
const char doc[] = "Welcome to my program";
struct argp argp = { NULL, NULL, NULL, doc };
The first one does not compile with the error:
main.c:5:40: error: initializer element is not constant
struct argp argp = { NULL, NULL, NULL, doc };
main.c:5:40: note: (near initialization for ‘argp.doc’)
But in my mind const char doc[]
was exactly the same as a constant pointer on char.
Note that both code were tested as global variables so in both case the lifetime of the variables should have been the same.
What am I missing?