Struct initialization - Compiller error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Struct initialization - Compiller error

Jump to solution
1,044 Views
martinkresta
Contributor I

Hi,

I am using Codewarrior 5.9 with target MC9S12XS128.

 

I am trying to initialize array of structures. But I end up with following error.

 

in header file:

typedef struct {

  uint8 mask;

  uint8 offset;

  Dio_PortType port;         

} Dio_ChannelGroupType;         // Definition of channel group


in another header file:

extern const Dio_ChannelGroupType DioConfigData[];


in .c file:

const Dio_ChannelGroupType DioConfigData[] = {

    {

        .mask = 0xF0U,     error: Expected: . * = - & ! ~ ++ -- -> [ ( IDENT CONSTANT STRING sizeof __alignof__ __va_sizeof__ __va_arg_type__

        .offset = 4U,

        .port = P_T,

    },  

    {

        .mask = 0x0FU,

        .offset = 0U,

        .port = P_A,

    }

}; 

 

This construction works without errors on the same place :

const Dio_ChannelGroupType DioConfigData[] = {

    {

        0xF0U,

        4U,

        P_T,

    },  

    {

        0x0FU,

        0U,

        P_A,

    }

};


I have no clue what is wrong with my code. Do you have any advice?

Thank you


Martin


 


Labels (1)
0 Kudos
1 Solution
566 Views
CrasyCat
Specialist III

Hello

The notation you are attempting to use is defined in ANSI C99 standard and is called designated initializer.

However CodeWarrior for HCS12 compiler is based on the ANSI C90 standard which does not support this feature.

So you need to use following notation to initialize your structure:

const Dio_ChannelGroupType DioConfigData[] = {

    {

        0xF0U,

        4U,

        P_T,

    },  

    {

        0x0FU,

        0U,

        P_A,

    }

};


CrasyCat

View solution in original post

0 Kudos
1 Reply
567 Views
CrasyCat
Specialist III

Hello

The notation you are attempting to use is defined in ANSI C99 standard and is called designated initializer.

However CodeWarrior for HCS12 compiler is based on the ANSI C90 standard which does not support this feature.

So you need to use following notation to initialize your structure:

const Dio_ChannelGroupType DioConfigData[] = {

    {

        0xF0U,

        4U,

        P_T,

    },  

    {

        0x0FU,

        0U,

        P_A,

    }

};


CrasyCat

0 Kudos