Re: C89, size_t, and long
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Wed, 14 Mar 2007 15:35:28 -0400
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
.
- 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
- C89, size_t, and long
- Prev by Date: Re: meaning of "empty pair" of parenthesis ?
- Next by Date: Re: size of pointers
- Previous by thread: Re: C89, size_t, and long
- Next by thread: Re: C89, size_t, and long
- Index(es):
Relevant Pages
|