🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #313

Re: size_t

#313
From: R. Vuurboom
Date: Mon, 10 Jul 1989 17:22
46 lines
2546 bytes
In article <1003@cbnewsl.ATT.COM> dfp@cbnewsl.ATT.COM (david.f.prosser) writes:
>In article <971@tukki.jyu.fi> tarvaine@tukki.jyu.fi (Tapani Tarvainen) writes:
>>Something related which I would call a bug is the behaviour of
>>calloc() that e.g., calloc(1000,1000) won't give an error or NULL but
>>silently truncates the product to 16960 (== 1000000 && 0x0ffff) and
>>allocates that amount.  What does the pANS say about overflow handling
>>in this situation?
>>-- 
>
>There is a general statement in section 4.1.6 for the arguments to the
>library functions.  It allows undefined behavior in the library if a
>function is passed arguments with invalid values, or values outside of
>the function's domain.  

True but not particularly relevant (me thinks) since each argument _is_
valid and well within (I hope!) the domain that size_t can handle.

>Since calloc() must produce an object with no more bytes than can be 
>counted in a size_t, 

Care to quote the relevant sentence? Doesn't seem to have made it into my
Jan 88 draft :-).


Quoting from the Mark Williams Ansi C - A lexical guide:

calloc allocates a portion of memory large enough to hold count items,
each of which is size bytes long. It then initializes every byte within
the portion to zero.

calloc returns a pointer to the portion allocated. The pointer is aligned for
any type of object. If it cannot allocate the amount of memory requested,
it returns NULL.

My guess is that the above implementation is broken.

In the above case, if you're using calloc to allocate memory for an array then
you can't use sizeof to find the size of your array (in bytes) since sizeof 
returns size_t. Could this be the source of confusion?

>Dave Prosser	...not an official X3J11 answer...

Roelof Vuurboom ...still not an official X3J11 answer...
-- 
Roelof Vuurboom  SSP/V3   Philips TDS Apeldoorn, The Netherlands   +31 55 432226
domain: roelof@idca.tds.philips.nl             uucp:  ...!mcvax!philapd!roelof
Technical Details
Message-ID: <149@ssp1.idca.tds.philips.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!usc!cs.utexas.edu!uunet!mcvax!hp4nl!philapd!ssp1!roelof
References: <934@tukki.jyu.fi> <845@cbnewsl.ATT.COM> <941@tukki.jyu.fi> <975@cbnewsl.ATT.COM> <971@tukki.jyu.fi> <1003@cbnewsl.ATT.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!usc!cs.utexas.edu!uunet!mcvax!hp4nl!philapd!ssp1!roelof
From: roelof@idca.tds.PHILIPS.nl (R. Vuurboom)
Newsgroups: comp.std.c
Subject: Re: size_t
Keywords: calloc, size_t
Message-ID: <149@ssp1.idca.tds.philips.nl>
Date: 10 Jul 89 17:22:47 GMT
References: <934@tukki.jyu.fi> <845@cbnewsl.ATT.COM> <941@tukki.jyu.fi> <975@cbnewsl.ATT.COM> <971@tukki.jyu.fi> <1003@cbnewsl.ATT.COM>
Organization: Philips Telecommunication and Data Systems, The Netherlands
Lines: 46