[ell-i-developers] Initializing a typedef struct inside a typedef struct

  • From: Jose Granados Vergara <jose.granados@xxxxxx>
  • To: "<ell-i-developers@xxxxxxxxxxxxx>" <ell-i-developers@xxxxxxxxxxxxx>
  • Date: Fri, 09 May 2014 20:24:07 +0000

I have these typedefs structs:

typedef struct {
    uint8_t  optionLength;
    uint8_t *optionValue;
}CoapOption;

typedef struct  {
CoapOption uriPath;
CoapOption uriQuery;
CoapOption contentFormat;
CoapOption accept;
}CoapOptions;

typedef struct
{
  uint8_t* token;
  CoapOptions options;
}CoapMsg;

When I do:
CoapOptions options = { { 0, NULL }, { 0, NULL }, { 0, NULL }, { 0, NULL } };

I have no compilation errors, but when I do

CoapMsg* coapMsg;
coapMsg->options = { { 0, NULL }, { 0, NULL }, { 0, NULL }, { 0, NULL } };

I get error: expected expression before '{' token

What could be the problem?

-Jose Granados
MSc Student.
Embedded Computing
University of Turku

Other related posts: