This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sizeof bugs...

As we all know... sizeof( typedef ) should return the size, in bytes, of its operand. If the operand is a type, such as a float, it must be enclosed in parentheses.

I found a bug in sizeof( tMyStruct ), where tMyStruct is a structure I typedef'ed that included an enum. sizeof was returning a value off by one from what I expected. This problem went away after replacing the enum with an unsigned int--both of which are supposed to be two bytes in size.

It appears that an enum is only one byte and not two bytes as documented in the C51 Compiler manual. In an attempt to verify this I tried sizeof( enum ). However, this produced a syntax error instead of returning the size of the operand. A second bug.

Can anyone else verify this... I'm using uVision2 v2.20a with C51 v6.20c.

Regards,

Mark Shelton
Remove "nospam." from the domain of my e-mail address to reply directly.

Parents
  • You don't even need to delve into the Release Notes - it's clearly stated in the manual (and has been for several revisions now).

    See the table of Data Types in Chapter 3, Language Extensions

    It is actually quite common for compilers to choose an appropriate size for enums according to the range of enum constants required.

    Note that this is known at compile time!

Reply
  • You don't even need to delve into the Release Notes - it's clearly stated in the manual (and has been for several revisions now).

    See the table of Data Types in Chapter 3, Language Extensions

    It is actually quite common for compilers to choose an appropriate size for enums according to the range of enum constants required.

    Note that this is known at compile time!

Children
  • Well, it's new to me as I've never come across it after 10+ years of C programming using a half dozen different compilers. I guess I can learn something new.

    I just updated from v6.02 to v6.20 and the manual that came with v6.02 clearly states, in the very table you mentioned, that an enum is two bytes. I guess I should have read the release notes and printed the new manual.

    Thanks,

    Mark