Re: C89, size_t, and long
- From: Yevgen Muntyan <muntyan.removethis@xxxxxxxx>
- Date: Wed, 14 Mar 2007 23:09:37 GMT
Eric Sosman wrote:
Yevgen Muntyan wrote On 03/14/07 15:57,:Eric Sosman wrote:If size_t is wider than long, the implementation cannotIt claims conformance to C90. It does not conform to C99.
conform to C89. [...]
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 notFrom your description, it cannot be a conforming C89
C89-conforming (it's an important thing, isn't it)? Or I do miss
something?
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 ...
- 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?
Answer to "why" may be wrong, but it won't change much if it's
already done. There is lot of code which assumes long
is big enough, and one must be aware of it (it's a real issue,
with real software).
There is more important thing to it. This single non-conformance
is simple: use appropriate types and you're good. But if MS broke
this thing (which breaks code, i.e. it's not some academic issue),
then what else is broken? It's a psychological issue (paranoia?).
- 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.
You're saying it's legitimate. But how is casting size_t
to unsigned long more legitimate than
int process_some_data (char *data, unsigned long len);
Yevgen
.
- Follow-Ups:
- Re: C89, size_t, and long
- From: Richard Bos
- 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
- Re: C89, size_t, and long
- From: Eric Sosman
- C89, size_t, and long
- Prev by Date: Re: ANSI C syntax ?
- Next by Date: Re: Good Design in C: Encapsulation
- Previous by thread: Re: C89, size_t, and long
- Next by thread: Re: C89, size_t, and long
- Index(es):
Relevant Pages
|