Re:A critique of "How to C in 2016"
by chrisseaton on Friday January 15, 2016 @06:11AM
(#10908511)
Maybe he's taking it very literally, as I think size_t is literally defined as 'the integer type of the result of the sizeof operator'. So it literally isn't defined as 'an integer capable of holding the >largest array index' as that's not the definition and words they use.
But if sizeof returns size_t, then your can't have indexes larger than that. Otherwise you could point beyond the largest in-memory object possible. (Using smallest (byte) indexing)
But yes, he may be arguing the definition rather than meaning.
Re:A critique of "How to C in 2016"
by dietrichepp on Friday January 15, 2016 @06:38AM
(#10908616)
The counterargument is actually relatively simple, because it's an argument over what the definition of size_t is, and you can simply go look to the C standard and find the definition there.
I understand.
If I change the argument to: size_t is capable of holding the largest array index", then this must be correct, or is there still something I missed?
Re:A critique of "How to C in 2016"
by dietrichepp on Friday January 15, 2016 @06:43AM
(#10908633)
Yes, that's correct.
>>No, it isn't.
Could anyone elaborate?
I don't see how could someone allocate more than SIZE_MAX bytes with (m/c/re)alloc since they all take size_t as an argument, and size_t is the type used for defining array sizes. Thus size_t can hold the largest array index (in fact it can hold the largest_index+1 since arrays are zero based). Any counterarguments?