C array initialization.
Posted
by chrisdew
on Stack Overflow
See other posts from Stack Overflow
or by chrisdew
Published on 2010-05-06T14:32:04Z
Indexed on
2010/05/06
14:48 UTC
Read the original article
Hit count: 306
Why does
static char *opcode_str[] = { "DATA"
, "DATA_REQUEST_ACK"
, "ACK_TIMER_EXPIRED"
, "ACK_UNEXPECTED_SEQ"
, "ACK_AS_REQUESTED"
} ;
work, but
static char **opcode_str = { "DATA"
, "DATA_REQUEST_ACK"
, "ACK_TIMER_EXPIRED"
, "ACK_UNEXPECTED_SEQ"
, "ACK_AS_REQUESTED"
} ;
fails with SEGV when opcode_str[0] is printf'd?
I think it's because the second listing has not allocated memory for the five element array of pointers, but I need a more comprehensive explanation.
All the best,
Chris.
© Stack Overflow or respective owner