03-08-2009, 01:13 PM
I would suggest a new rule for MISRA C.
"Do not use the sizeof() operator".
Output seems to be compiler dependent, e.g. TI compiler for TMS320C2x/C2xx/C5x series returns the number of 16bit units.
They (TI) claim, that there is an ambiguity in the ANSI C definition:
- sizeof() shall return the number of bytes
- sizeof(char) shall return 1
As they implement a char as 16 bit, their solution of the dilemma is to define a byte as 16 bit.
This sounds problematic and will cause issues while porting code, which uses the sizeof() operator.
"Do not use the sizeof() operator".
Output seems to be compiler dependent, e.g. TI compiler for TMS320C2x/C2xx/C5x series returns the number of 16bit units.
They (TI) claim, that there is an ambiguity in the ANSI C definition:
- sizeof() shall return the number of bytes
- sizeof(char) shall return 1
As they implement a char as 16 bit, their solution of the dilemma is to define a byte as 16 bit.
This sounds problematic and will cause issues while porting code, which uses the sizeof() operator.
<t></t>