[Ilugc] Re: need help in 64-bit code

  • From: urwithsudheer@xxxxxxxxx (sudheer)
  • Date: Fri May 5 23:47:22 2006

Hi Thomas,

Thank you  and all very much

Thanks
Sudheer.A

Mike DeKoker wrote:

--- sudheer <urwithsudheer@xxxxxxxxx> wrote:

 

Hi Thomas,

Thomas Petazzoni wrote:

   

Hi,

Le Fri, 05 May 2006 18:02:48 +0530,
sudheer <urwithsudheer@xxxxxxxxx> a ?crit :



     

To have  the compatability i have used  the macro
       

CONFIG_X86_64 in 
   

.config  .
  

       

Why do you need to differentiate code executed on
     

32 bits platforms
from code executed on 64 bits platform ? Generally
speaking, your code
   

should be portable, and not rely on CONFIG_X86_64
     

or other options of
   

the same kind.



     

I want to assign some data to a long pointer
variable SysAdddr.

#ifdef CONFIG_64
*(SysAddr + num_items) = (0xaa55aa55aa000000 +
num_items);
#else
*(SysAddr + num_items) = (0x11220000 + (num_items));
#endif
If it is 64 but system i should assign 64 bit or
else 32 bit data.
Can i have any other option/method ?

Thanks
Sudheer



   


As previously mentioned your code should be portable
and not rely on architecture specific things like
pointer size. That being said, here's another way to
do this at roughly compile time:

if (sizeof(long) > 4)
{
*(SysAddr + num_items) = 
  (0xaa55aa55aa000000 + num_items);
}
else
{
*(SysAddr + num_items) = 
  (0x11220000 + (num_items));
}

The optimizer should remove the extraneous branch of
code.

Mike DeKoker
Signatec, Inc.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com ;

 


Other related posts: