Re: C89, size_t, and long
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Wed, 14 Mar 2007 18:04:35 -0400
Yevgen Muntyan wrote On 03/14/07 15:57,:
Eric Sosman wrote:
If size_t is wider than long, the implementation cannot
conform to C89. [...]
It claims conformance to C90. It does not conform to C99.
In that case, the claim is incorrect, and testably so:
size_t u = -1;
unsigned long v = u;
assert (u == v);
[...] Anyway, is MS Win64 implementation not
C89-conforming (it's an important thing, isn't it)? Or I do miss
something?
From your description, it cannot be a conforming C89
implementation. Is that important? Well, to whom?
Well, to people who want to write code which would work on win64.
Observe that this nonconformance only affects code that
does any of
- Type-punning via unions or pointers to access a size_t
object as an unsigned long or vice versa (or similar punning
between ptrdiff_t and signed long). Such code is broken already
under all versions of the Standard, so it doesn't bother me if
MS causes additional breakage.
- Computing sizes > ULONG_MAX bytes (>= 4GB, in this case)
and converting them to unsigned long. First, you'd need to
have a reason to compute such large sizes; all right, on a
64-bit system I'll grant that such reasons may arise. But
then you'd need to write unsigned long instead of size_t to
get into trouble; why would you do that?
- To answer the question, you might do that to print the
size_t value using "%lu" or something of the kind. In this
case, you could get the wrong answer printed, which might or
might not affect the behavior of the rest of the program. As
far as I can imagine, this is the only case you need to worry
about, the only case in "legitimate" code where the fact that
size_t is wider than unsigned long could cause trouble. Be
on your guard!
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- References:
- C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Eric Sosman
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Eric Sosman
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- C89, size_t, and long
- Prev by Date: Re: What is C suitable for nowadays?
- Next by Date: Re: [OT] Is Islam Really a Religion of Terror?
- Previous by thread: Re: C89, size_t, and long
- Next by thread: Re: C89, size_t, and long
- Index(es):
Relevant Pages
|