How to use const or enum in struct?

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

How to use const or enum in struct?

Jump to solution
1,178 Views
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

Labels (1)
1 Solution
1,018 Views
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};

View solution in original post

2 Replies
1,019 Views
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,018 Views
aaronlee
Contributor V

Dear Edward,

Thank you very much.

Best Regard,

Aaron

0 Kudos
Reply