Re: C89, size_t, and long



Yevgen Muntyan wrote On 03/14/07 15:14,:
Eric Sosman wrote:

Yevgen Muntyan wrote On 03/14/07 14:26,:
[...]
Was it required by C89 that result of sizeof() fits into unsigned long,
and that pointer subtraction result fits into long? [...]
If yes, then MS
Win64 implementation is not C89-conforming (while sizeof case may be
arguable, I guess, we certainly can ask to malloc more than ULONG_MAX
bytes, and get pointer arithmetics which needs more than (unsigned)
long). [...]

I don't know MS' Win64 implementation well enough to comment
on whether it's broken or not.

It has 32-bit long, same as int, and naturally 64-bit size_t.

If size_t is wider than long, the implementation cannot
conform to C89. It could, however, conform to C99, with
size_t being as wide as long long or as some other wide type.
One of the (many) things I don't know about MS Win64 is what
standards it claims to conform to.

As for programs that assumed
size_t and ptrdiff_t were no wider than long, no: They were not
broken under C89's rules, because C89 implied the truth of the
assumption.

Then these programs may be broken on Win64, right? Say, this code:

void do_something (void *buf, unsigned long len)
{
memset (buf, 1, len);
}

int main (void)
{
size_t i;
size_t size = BIG_NUMBER;
char *p = malloc (size);
if (p)
{
do_something (p, size);
assert (p[size-1]);
}
return 0;
}

If malloc() succeeds, this program works under C89 but
might not work on a C99 implementation.

[...] 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?

--
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 sizeof() fits into unsigned long, ... and that pointer subtraction result fits into long? ...
    (comp.lang.c)
  • Re: C89, size_t, and long
    ... If size_t is wider than long, ... It claims conformance to C90. ... It does not conform to C99. ... it cannot be a conforming C89 ...
    (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)