Struct initialization - Compiller error

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Struct initialization - Compiller error

ソリューションへジャンプ
1,675件の閲覧回数
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


 


ラベル(1)
0 件の賞賛
返信
1 解決策
1,197件の閲覧回数
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 件の賞賛
返信
1 返信
1,198件の閲覧回数
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 件の賞賛
返信