Big numbers

Status
Not open for further replies.

electroRF

Member
Hi,
I wanna mask the 31th bit of a register.

So I wanna set a DEFINE:

What is the difference between:

C:
#define RUNBIT 0x80000000

and

C:
#define RUNBIT 0x80000000L

I'm trying to figure out if I need that L.

Thank you.
 
Depends on the compiler.... If you leave it in you'll be safe.... Some compilers use short int ( 16 bit ) constants unless specified..
 
Should not matter.

On 32-bit processor, long int is the same as int anyway.

On 16-bit processor, the constant will be 32-bit because it doesn't fit into 16 bits.
 
Should not matter.

On 32-bit processor, long int is the same as int anyway.

On 16-bit processor, the constant will be 32-bit because it doesn't fit into 16 bits.

I would not blindly trust that. Standard says that int must be at least 16 bits and long int 32 bits. Compilers for microcontrollers do not always comply with standards. The original question is kind of lazy.. true answer on my opinion is that you should know your compiler. If the compiler does not have proper documentation then you should switch compiler.

I always use UL with big numbers.. just in case. It doesn't do any harm, just informs the compiler. And I always use c99 standard types: uint8_t, uint16_t, etc. I never use int, long int etc.. those are obsolete. That is my opinion. For string arrays I still use "char". That is the only variable that I trust the compiler.

If you say
char c;
sizeof(c); /* sizeof returns 1 */
that variable is 1 byte. But, if you say
sizeof('c') /* sizeof returns 2 */
that constant is 2 bytes.
 
Last edited:

Actually.. This is spot on!.... I have been slapped in the face too often because a compiler doesn't comply!!! There is no excuse as all these types are already defined..... XC8 has an issue with signed / unsigned.. As someone said in a post... XC8 doesn't default to signed..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…