Re: C89, size_t, and long



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
.



Relevant Pages

  • Re: Why const without type compiles?
    ... that gcc makes no claim to conform to any version of the C standard ... Gcc currently has support for five different C-like ... The C89 standard merely requires "a diagnostic". ... diagnose any other problems in the translation unit). ...
    (comp.lang.c)
  • Re: C89, size_t, and long
    ... Was it required by C89 that result of sizeoffits into unsigned long, ... and that pointer subtraction result fits into long? ... Win64 implementation is not C89-conforming (while sizeof case may be ... It could, however, conform to C99, with ...
    (comp.lang.c)
  • Re: C89, size_t, and long
    ... It does not conform to C99. ... it cannot be a conforming C89 ... size_t is wider than unsigned long could cause trouble. ... to unsigned long more legitimate than ...
    (comp.lang.c)
  • Re: Commandline compiler for windows?
    ... But does lcc-win *conform* to C89? ... you were under the impression that lcc-win conformed to either Standard, ...
    (comp.lang.c)