comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: A curiosity...
Date: Fri, 05 Dec 2008 08:37:22 -0800
Date: 2008-12-05T08:37:22-08:00	[thread overview]
Message-ID: <ln4p1itw71.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 87r64naw36.fsf@willow.rfc1149.net

Samuel Tardieu <sam@rfc1149.net> writes:
>>>>>> "Ludovic" == Ludovic Brenta <ludovic@ludovic-brenta.org> writes:
> Ludovic> And I think this rule is responsible for the "limitation"
> Ludovic> that all current processor architectures use addresses which
> Ludovic> are the same size as integers. Before the advent of C,
> Ludovic> address size and word size were not necessarily the same; now
> Ludovic> they always are, and that's *only* for compatibility with C.
>
> Certainly not. For example, on a x86_64 Linux machine with GCC, you
> can try the following snippet (untested):
>
> #include <stdio.h>
> int main()
> {
>   printf("integer size is %d, pointer size is %d\n",
>          sizeof(int), sizeof(void*));
>   return 0;
> }
>
> You should get respectively 4 and 8.
[...]

You get undefined behavior, since "%d" expects an argument of type int
and you're giving it an argument of type size_t.  And on the system in
question, it's very likely that size_t is bigger than int, so this
could cause real problems.

    printf("integer size is %lu, pointer size is %lu\n",
           (unsigned long)sizeof(int), (unsigned long)sizeof(void*));

or, in C99:

    printf("integer size is %zu, pointer size is %zu\n",
           sizeof(int), sizeof(void*));

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  parent reply	other threads:[~2008-12-05 16:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 20:47 A curiosity mockturtle
2008-12-04 21:17 ` Adam Beneschan
2008-12-04 21:48   ` Hyman Rosen
2008-12-04 22:04     ` Ludovic Brenta
2008-12-04 22:10       ` Ludovic Brenta
2008-12-04 22:24         ` Hyman Rosen
2008-12-05  8:02         ` Samuel Tardieu
2008-12-05 11:51           ` Peter C. Chapin
2008-12-05 13:09           ` Martin Krischik
2008-12-05 15:15             ` Hyman Rosen
2008-12-06 13:26             ` Peter C. Chapin
2008-12-05 16:37           ` Keith Thompson [this message]
2008-12-04 22:19       ` Hyman Rosen
2008-12-05  9:03       ` Georg Bauhaus
2008-12-04 22:30 ` Randy Brukardt
2008-12-04 22:57   ` Hyman Rosen
2008-12-05 16:42     ` Keith Thompson
2008-12-05 16:57       ` Hyman Rosen
2008-12-05 20:20         ` Keith Thompson
2008-12-05 20:59           ` Adam Beneschan
2008-12-06 22:53             ` Hyman Rosen
2008-12-06 23:15               ` Gary Scott
2008-12-08 15:39                 ` Hyman Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox