[omniORB] CORBA::Long
David Byron
dbyron@coactive.com
Mon, 4 Mar 2002 07:52:49 -0800
I think the only way to make this printf call portable
(and warning free) is to cast number to a type for which
there's a corresponding format specifier. If CORBA::Long
happens to be an int on your platform, you could cast
number with (int) and it would work. On platforms where
CORBA::Long is really a long, this would be a dangerous
cast -- you could lose information.
So, I think the printf needs to be:
printf("number = %ld\n", (unsigned long)number);
and then it's safe no matter whether number is an int or
long underneath. I know the cast is ugly. Casts bug me.
In this case, I think it may be the only safe way.
I'm pretty sure this still works for 64 bit machines, but I
don't have any first hand experience with them.
-DB
---
David Byron dbyron@coactive.com
Coactive Networks, Inc. http://www.coactive.com
28 Liberty Ship Way voice:(415)289-7800
Sausalito, CA 94965 fax:(415)289-1320
> -----Original Message-----
> From: Luke Deller [mailto:ldeller@xplantechnology.com]
> Sent: Sunday, March 03, 2002 10:56 PM
> To: omniorb-list@uk.research.att.com
> Subject: [omniORB] CORBA::Long
>
>
> Hi,
>
> Why is CORBA::Long typedef'ed to "long" rather than "int" on 32-bit
> architectures?
>
> This makes using the printf/scanf family of functions with
> CORBA::Long quite awkward...
>
> With gcc2.96 on x86, the following code produces a warning
> "int format, Long arg (arg 2)":
>
> CORBA::Long number = 3;
> printf("number = %d\n", number);
>
> but the required fix [changing %d to %ld] would make this
> code snippet not 64-bit clean.
>
> Would it be possible to change CORBA::Long to be "int"?
>
> Regards,
> Luke.