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
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
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};
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};