Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: malloc and maximum size |
| Date | 2011-10-14 16:38 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <4E989DDC.8040900@verizon.net> (permalink) |
| References | (2 earlier) <44zkh37goi.fsf@be-well.ilk.org> <4E985803.8070300@verizon.net> <44r52f760i.fsf@be-well.ilk.org> <4E988AC3.6050701@verizon.net> <44mxd373wl.fsf@be-well.ilk.org> |
On 10/14/2011 03:46 PM, Lowell Gilbert wrote: > James Kuyper <jameskuyper@verizon.net> writes: > >> On 10/14/2011 03:00 PM, Lowell Gilbert wrote: >>> James Kuyper <jameskuyper@verizon.net> writes: >>> >>>> On 10/14/2011 11:10 AM, Lowell Gilbert wrote: >>>> ... >>>>> Does SIZE_MAX have to be the largest value representable in a size_t? >>>>> The standard just says that it's the "maximum value" for the type, >>>> >>>> What distinction do you see between "largest value representable" if a >>>> type and "maximum value" for a type? The phrases seem synonymous to me. >>> >>> Certainly there's no difference in *most* cases. >>> >>> For size_t, the type is just defined as the output type for sizeof, >>> which is defined in turn as yielding the size of its operand. So I can >>> see an argument that the "maximum value" of a size_t could be viewed as >>> the largest value that sizeof could possibly yield on the particular >>> implementation. >> >> Well, the maximum value returnable by sizeof has to be the same as the >> maximum value representable by size_t: >> >> sizeof(char[(size_t)-1]) == (size_t)(-1) > > Assuming I understand what you're getting at, you're begging the > question here. [But the expression doesn't make sense to me, so > the assumption may well be wrong.] I had not intended to beg the question. Per 6.3.1.3p2, (size_t)(-1) is precisely "the maximum value that can be represented" as a size_t. char[(size_t)(-1)] is an array type whose size in bytes is (size_t)(-1). sizeof(char[(size_t)(-1)]) must therefore yield a value which is (size_t)(-1). Therefore, the largest value that sizeof could possibly yield must be (size_t)(-1), the same as the maximum representable value. ... >> However, there's no possible basis that I'm aware of for rejecting >> sizeof(char[(size_t)-1]). > > I assume you mean SIZE_MAX rather than (size_t), No, in don't mean SIZE_MAX, since I was trying to address your claim that it can be less than maximum representable value. I didn't mean (size_t), either, which is no more than a parenthesized type - I presume that was an editing error? I meant (size_t)(-1), which is guaranteed by the standard to be the maximum representable value. > ... in which case I agree. > But that doesn't mean SIZE_MAX has to be the largest value a size_t can > hold, if there are other limits on how big an object can be. The key point is that sizeof acts on types, not objects. Even when you write "sizeof expression", and expression is an lvalue referring to an object, it doesn't look into the expression to determine which object it refers to; it just looks at the type of the expression. It doesn't care whether or not there's any actual object of that type. sizeof(int) == sizeof *(int*)0, even though the standard prohibits (int*)0 from pointing at any actual object. >>> ... Of course, that can be (and, indeed, often is) smaller >>> than a size_t could represent. >> >> With respect to your claim "often is" - can you cite any implementation >> where the equality expression given above is NOT true? > > I think you're misreading my claim. There certainly are systems with > architectural limitations on how big an object can be, well short of > what fits in a size_t. And sizeof(char[(size_t)(-1)]) exceeds none of those limitations, because it doesn't cause the creation of any object of the specified type. > For example, the machine I'm posting from has 32-bit words, from which > it gets a 4-gigabyte range for its size_t. However, the operating > system reserves some of the address space, so no program can ever have > more than 3 gigabytes. As a result, sizeof can *never* return more than > 3 gigabytes. Not even sizeof(char[3500000000])? For an implementation where (size_t)(-1) is 4294967295, what gives that implementation permission to do anything with that expression other than yield a value of (size_t)3500000000? The implementation is free to issue a diagnostic, of course, but not to reject the code. > ... This prompted me to wonder whether it would be legitimate > for the system's SIZE_MAX to be 3 gigabytes. > > Am I making more sense now? Not yet. You seem to have missed the point I was making, while I think I understand yours perfectly. Is my point clearer now?
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
malloc and maximum size "V.Subramanian, India" <subramanian100in@yahoo.com> - 2011-10-14 06:31 -0700
Re: malloc and maximum size gordonb.pey1d@burditt.org (Gordon Burditt) - 2011-10-14 09:45 -0500
Re: malloc and maximum size Lowell Gilbert <lgusenet@be-well.ilk.org> - 2011-10-14 11:10 -0400
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 11:40 -0400
Re: malloc and maximum size Lowell Gilbert <lgusenet@be-well.ilk.org> - 2011-10-14 15:00 -0400
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 15:17 -0400
Re: malloc and maximum size Lowell Gilbert <lgusenet@be-well.ilk.org> - 2011-10-14 15:46 -0400
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 16:38 -0400
Re: malloc and maximum size Ike Naar <ike@iceland.freeshell.org> - 2011-10-14 21:59 +0000
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 18:26 -0400
Re: malloc and maximum size Lowell Gilbert <lgusenet@be-well.ilk.org> - 2011-10-14 18:42 -0400
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 16:27 -0700
Re: malloc and maximum size Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-14 20:41 -0400
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 18:31 -0700
Re: malloc and maximum size Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-15 02:58 +0100
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 22:11 -0700
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 22:59 -0400
Re: malloc and maximum size Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-14 23:44 -0400
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 22:56 -0700
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-15 07:52 -0400
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:54 -0800
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:51 -0800
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 22:51 -0400
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 22:48 -0700
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-15 07:54 -0400
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-15 11:25 -0700
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-15 21:21 -0400
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 17:41 -0800
Re: malloc and maximum size Kaz Kylheku <kaz@kylheku.com> - 2012-01-25 02:11 +0000
Re: malloc and maximum size Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-15 11:50 -0400
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-15 21:38 -0400
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 17:33 -0800
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 17:06 -0800
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:58 -0800
Re: malloc and maximum size Kaz Kylheku <kaz@kylheku.com> - 2012-01-25 01:23 +0000
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 16:31 -0800
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 22:20 -0400
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 16:03 -0700
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 23:01 -0400
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 17:35 -0800
Re: malloc and maximum size Kaz Kylheku <kaz@kylheku.com> - 2012-01-25 02:33 +0000
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 17:14 -0800
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:45 -0800
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:32 -0800
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2012-01-25 02:40 -0800
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 17:27 -0800
Re: malloc and maximum size Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-14 16:17 -0400
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 16:52 -0400
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 16:12 -0700
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 23:04 -0400
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:36 -0800
Re: malloc and maximum size Ike Naar <ike@iceland.freeshell.org> - 2011-10-14 16:49 +0000
Re: malloc and maximum size James Kuyper <jameskuyper@verizon.net> - 2011-10-14 11:05 -0400
Re: malloc and maximum size Nobody <nobody@nowhere.com> - 2011-10-14 16:11 +0100
Re: malloc and maximum size Kenneth Brody <kenbrody@spamcop.net> - 2011-10-14 12:24 -0400
Re: malloc and maximum size jt@toerring.de (Jens Thoms Toerring) - 2011-10-14 17:10 +0000
Re: malloc and maximum size Stephen Sprunk <stephen@sprunk.org> - 2011-10-14 13:43 -0500
Re: malloc and maximum size Keith Thompson <kst-u@mib.org> - 2011-10-14 12:03 -0700
Re: malloc and maximum size jt@toerring.de (Jens Thoms Toerring) - 2011-10-14 20:36 +0000
Re: malloc and maximum size Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:26 -0800
Re: malloc and maximum size Seebs <usenet-nospam@seebs.net> - 2011-10-17 17:21 +0000
Re: malloc and maximum size Shao Miller <sha0.miller@gmail.com> - 2012-01-24 23:49 -0500
Re: malloc and maximum size Shao Miller <sha0.miller@gmail.com> - 2012-01-24 23:55 -0500
csiph-web