Please note: We are aware of an issue affecting replies on the Arm Community forums, which may not be loading as expected.

We apologize for any inconvenience and appreciate your patience while we investigate and work to resolve the issue.

Thank you for your understanding.


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

C question

Hello,

On an ARM7, why isn't the value of 'my_char' truncated to the range of a signed char?

char my_char = 240;

I see that 'my_char' is stored in a register - fine, but why isn't that register ANDed with 127? The range of a char type on an ARM7 machine is -128..+127.

Thanks

Parents
  • On an ARM7, why isn't the value of 'my_char' truncated to the range of a signed char?

    Because it's machine- and compiler-dependent whether char is signed or unsigned.

    If you require a variable to be a signed char, you will need to declare it as such. Alternatively, if you require variables declared as plain char to be signed or unsigned, you need to look whether the compiler offers an appropriate setting.

Reply
  • On an ARM7, why isn't the value of 'my_char' truncated to the range of a signed char?

    Because it's machine- and compiler-dependent whether char is signed or unsigned.

    If you require a variable to be a signed char, you will need to declare it as such. Alternatively, if you require variables declared as plain char to be signed or unsigned, you need to look whether the compiler offers an appropriate setting.

Children