How to use const or enum in struct?

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

How to use const or enum in struct?

ソリューションへジャンプ
1,182件の閲覧回数
aaronlee
Contributor V

Hi,

How to use const in struct?

struct SDCardState

{

   const uint16_t initTimeout=2000;

   enum uint8_t CardType {

      CardTypeSD1,

      CardTypeSD2,

      CardTypeSDHC,

   }

}

We got a error as follow:

';' expected 

Best Regard,

Aaron

ラベル(1)
1 解決策
1,022件の閲覧回数
kef2
Senior Contributor V

Lots of problems in your snippet. Please make sure first that uint16_t and uint8_t are defined.

1. initialized can't be specified inside the struct. 

2. enum is already type, it can't be uint8_t or uint16-t, it's just enum, which has as many bits as required to store any of enumerated values in your list, 8 bits could be enough in one case, could be not enough in another case.

Provided uint16_t and unit8_t are defined:

struct SDCardState

{

   const uint16_t initTimeout;

 

   enum CardType {

      CardTypeSD1,

      CardTypeSD2,

      CardTypeSDHC,

   }

} instance = {2000};

元の投稿で解決策を見る

2 返答(返信)
1,023件の閲覧回数
kef2
Senior Contributor V

Lots of problems in your snippet. Please make sure first that uint16_t and uint8_t are defined.

1. initialized can't be specified inside the struct. 

2. enum is already type, it can't be uint8_t or uint16-t, it's just enum, which has as many bits as required to store any of enumerated values in your list, 8 bits could be enough in one case, could be not enough in another case.

Provided uint16_t and unit8_t are defined:

struct SDCardState

{

   const uint16_t initTimeout;

 

   enum CardType {

      CardTypeSD1,

      CardTypeSD2,

      CardTypeSDHC,

   }

} instance = {2000};

1,022件の閲覧回数
aaronlee
Contributor V

Dear Edward,

Thank you very much.

Best Regard,

Aaron

0 件の賞賛
返信