decimal constants

J

junky_fellow

Consider the following piece of code:
Note: The size of long is 64 bits on my processor.

#define MYCONSTANT 0x80000000UL

int main(void)
{
unsigned long i = 0x1000;

i &= ~MYCONSTANT;


}

My question is which is better,
#define MYCONSTANT 0x80000000UL
or
#define MYCONSTANT 0x80000000L


Thanx for any help in advance ....
 
V

Vladimir S. Oka

Consider the following piece of code:
Note: The size of long is 64 bits on my processor.

#define MYCONSTANT 0x80000000UL

int main(void)
{
unsigned long i = 0x1000;

i &= ~MYCONSTANT;


}

My question is which is better,
#define MYCONSTANT 0x80000000UL
or
#define MYCONSTANT 0x80000000L


Thanx for any help in advance ....

Size of long being 64 bits you'd get the same result either way
(0x80000000 being the same as 0x0000000080000000).

However, if you declare i as unsigned long, then MYCONSTANT is most
naturally a UL as well, especially if you don't want to be bitten
porting to a machine where long is shorter, and also especially if
MYCONSTANT is going to be used non-negated as well.

Cheers

Vladimir
 
V

Vladimir S. Oka

> Consider the following piece of code:
> Note: The size of long is 64 bits on my processor.
>
> #define MYCONSTANT 0x80000000UL
>
> int main(void)
> {
> unsigned long i = 0x1000;
>
> i &= ~MYCONSTANT;
>
>
> }
>
> My question is which is better,
> #define MYCONSTANT 0x80000000UL
> or
> #define MYCONSTANT 0x80000000L
>
>
> Thanx for any help in advance ....
>

Size of long being 64 bits you'd get the same result either way
(0x80000000 being the same as 0x0000000080000000).

However, if you declare i as unsigned long, then MYCONSTANT is most
naturally a UL as well, especially if you don't want to be bitten
porting to a machine where long is shorter, and also especially if
MYCONSTANT is going to be used non-negated as well.

Cheers

Vladimir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top