All of lore.kernel.org
 help / color / mirror / Atom feed
* size_t and printk and Xen
@ 2008-10-11 14:05 Dan Magenheimer
  2008-10-12  9:22 ` Keir Fraser
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Magenheimer @ 2008-10-11 14:05 UTC (permalink / raw)
  To: Xen-Devel (E-mail)

I am adding code in Xen that printk's a size_t and find that
I can't write code (short of ifdef'ing) that compiles on
both 32-bit and 64-bit because size_t is typedef'd in Xen as an
unsigned long.  C.f.

http://www.velocityreviews.com/forums/t438359-portable-way-to-printf-a-sizet-instance.html

It appears that the %z format is understood by Xen printk.

Is the typedef historical and should be removed?  Or is it
necessary for some (older?) compilers?

If it is not going to be removed, is there a workaround
(other than ifdef'ing)?

Thanks,
Dan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: size_t and printk and Xen
  2008-10-11 14:05 size_t and printk and Xen Dan Magenheimer
@ 2008-10-12  9:22 ` Keir Fraser
  2008-10-12  9:41   ` Keir Fraser
  0 siblings, 1 reply; 7+ messages in thread
From: Keir Fraser @ 2008-10-12  9:22 UTC (permalink / raw)
  To: Dan Magenheimer, Xen-Devel (E-mail)

On 11/10/08 15:05, "Dan Magenheimer" <dan.magenheimer@oracle.com> wrote:

> I am adding code in Xen that printk's a size_t and find that
> I can't write code (short of ifdef'ing) that compiles on
> both 32-bit and 64-bit because size_t is typedef'd in Xen as an
> unsigned long.  C.f.

Cast to an int or to a long? Use %z?

> http://www.velocityreviews.com/forums/t438359-portable-way-to-printf-a-sizet-i
> nstance.html
> 
> It appears that the %z format is understood by Xen printk.
> 
> Is the typedef historical and should be removed?  Or is it
> necessary for some (older?) compilers?

Removing it would break the build, I think.

 -- Keir

> If it is not going to be removed, is there a workaround
> (other than ifdef'ing)?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: size_t and printk and Xen
  2008-10-12  9:22 ` Keir Fraser
@ 2008-10-12  9:41   ` Keir Fraser
  2008-10-12 17:44     ` Dan Magenheimer
  0 siblings, 1 reply; 7+ messages in thread
From: Keir Fraser @ 2008-10-12  9:41 UTC (permalink / raw)
  To: Dan Magenheimer, Xen-Devel (E-mail)

On 12/10/08 10:22, "Keir Fraser" <keir.fraser@eu.citrix.com> wrote:

>> 
>> Is the typedef historical and should be removed?  Or is it
>> necessary for some (older?) compilers?
> 
> Removing it would break the build, I think.

I'm no particular fan of size_t in hypervisor interfaces though. So, for
example, switching xmalloc() interfaces to use unsigned int instead would be
fine by me, and this would sidestep the issue perhaps?

 -- Keir

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: size_t and printk and Xen
  2008-10-12  9:41   ` Keir Fraser
@ 2008-10-12 17:44     ` Dan Magenheimer
  2008-10-12 17:57       ` Keir Fraser
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Magenheimer @ 2008-10-12 17:44 UTC (permalink / raw)
  To: Keir Fraser, Xen-Devel (E-mail)

> On 12/10/08 10:22, "Keir Fraser" <keir.fraser@eu.citrix.com> wrote:
> 
> >> 
> >> Is the typedef historical and should be removed?  Or is it
> >> necessary for some (older?) compilers?
> > 
> > Removing it would break the build, I think.
> 
> I'm no particular fan of size_t in hypervisor interfaces 
> though. So, for
> example, switching xmalloc() interfaces to use unsigned int 
> instead would be
> fine by me, and this would sidestep the issue perhaps?

I think C99 size_t may have compile-time type-checking uses so
I'd be hesitant to remove it entirely.  I do suspect the typedef
pre-dates the addition to Xen of a more modern printk, but
I suppose we have bigger fish to fry and using %lu in the
printk format string and an unsigned-long cast in the argument
list is annoying but works.

Dan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: size_t and printk and Xen
  2008-10-12 17:44     ` Dan Magenheimer
@ 2008-10-12 17:57       ` Keir Fraser
  2008-10-12 18:12         ` Dan Magenheimer
  0 siblings, 1 reply; 7+ messages in thread
From: Keir Fraser @ 2008-10-12 17:57 UTC (permalink / raw)
  To: Dan Magenheimer, Xen-Devel (E-mail)

On 12/10/08 18:44, "Dan Magenheimer" <dan.magenheimer@oracle.com> wrote:

>> I'm no particular fan of size_t in hypervisor interfaces
>> though. So, for
>> example, switching xmalloc() interfaces to use unsigned int
>> instead would be
>> fine by me, and this would sidestep the issue perhaps?
> 
> I think C99 size_t may have compile-time type-checking uses so
> I'd be hesitant to remove it entirely.

Can you give a concrete example of how it helps us to use it within the
xmalloc interfaces? As far as I'm aware it's not useful at all, but I could
certainly be wrong as this aspect of the C spec is not something I've ever
really investigated.

 -- Keir

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: size_t and printk and Xen
  2008-10-12 17:57       ` Keir Fraser
@ 2008-10-12 18:12         ` Dan Magenheimer
  2008-10-13 10:02           ` Christoph Egger
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Magenheimer @ 2008-10-12 18:12 UTC (permalink / raw)
  To: Keir Fraser, Xen-Devel (E-mail)

> >> I'm no particular fan of size_t in hypervisor interfaces
> >> though. So, for
> >> example, switching xmalloc() interfaces to use unsigned int
> >> instead would be
> >> fine by me, and this would sidestep the issue perhaps?
> > 
> > I think C99 size_t may have compile-time type-checking uses so
> > I'd be hesitant to remove it entirely.
> 
> Can you give a concrete example of how it helps us to use it 
> within the
> xmalloc interfaces? As far as I'm aware it's not useful at 
> all, but I could
> certainly be wrong as this aspect of the C spec is not 
> something I've ever
> really investigated.

No, I can't.  IIRC it has something to do with portability to
unusual platforms.  Perhaps someone else with more knowledge
of C99 can comment on whether size_t is useful in Xen or we
should just avoid using it.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: size_t and printk and Xen
  2008-10-12 18:12         ` Dan Magenheimer
@ 2008-10-13 10:02           ` Christoph Egger
  0 siblings, 0 replies; 7+ messages in thread
From: Christoph Egger @ 2008-10-13 10:02 UTC (permalink / raw)
  To: xen-devel; +Cc: Dan Magenheimer, Keir Fraser

On Sunday 12 October 2008 20:12:33 Dan Magenheimer wrote:
> > >> I'm no particular fan of size_t in hypervisor interfaces
> > >> though. So, for
> > >> example, switching xmalloc() interfaces to use unsigned int
> > >> instead would be
> > >> fine by me, and this would sidestep the issue perhaps?
> > >
> > > I think C99 size_t may have compile-time type-checking uses so
> > > I'd be hesitant to remove it entirely.
> >
> > Can you give a concrete example of how it helps us to use it
> > within the
> > xmalloc interfaces? As far as I'm aware it's not useful at
> > all, but I could
> > certainly be wrong as this aspect of the C spec is not
> > something I've ever
> > really investigated.
>
> No, I can't.  IIRC it has something to do with portability to
> unusual platforms.  Perhaps someone else with more knowledge
> of C99 can comment on whether size_t is useful in Xen or we
> should just avoid using it.

NetBSD uses %zi for ssize_t and %zu for size_t.
%z doesn't exist.

Christoph

-- 
AMD Saxony, Dresden, Germany
Operating System Research Center

Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
   Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
   AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
   Dr. Hans-R. Deppe, Thomas McCoy

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-10-13 10:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-11 14:05 size_t and printk and Xen Dan Magenheimer
2008-10-12  9:22 ` Keir Fraser
2008-10-12  9:41   ` Keir Fraser
2008-10-12 17:44     ` Dan Magenheimer
2008-10-12 17:57       ` Keir Fraser
2008-10-12 18:12         ` Dan Magenheimer
2008-10-13 10:02           ` Christoph Egger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.