Re: advantage of using typedefs



Mark McIntyre <markmcintyre@xxxxxxxxxxx> writes:
> On Sat, 28 Jan 2006 19:32:56 GMT, in comp.lang.c , Keith Thompson
> <kst-u@xxxxxxx> wrote:
>>Mark McIntyre <markmcintyre@xxxxxxxxxxx> writes:
>>> On 28 Jan 2006 00:50:55 -0800, in comp.lang.c ,
>>> "junky_fellow@xxxxxxxxxxx" <junky_fellow@xxxxxxxxxxx> wrote:
>>>
>>>>I believe unsigned long long should be highest possible integer type ?
>>>>Or am I wrong ?
>>>
>>> You're right, but the size of long long varies from platform to
>>> platform
>>
>>Yes, but if you want the biggest unsigned integer type, you have to
>>accept that its size is going to vary.
>
> ... which was my point.

Then I'm confused. junky_fellow's question was:

But if this is the case (ie we need the biggest possible unsigned
integer to hold offset ) then why not declare unsigned long long
offset

and you replied:

Because then its size would vary from platform to platform, and on
a c90 implementation it would be an error.

The second point is valid (except for the many C90 implementations
that provide "long long" as an extension), but I don't see what you're
getting at with the first point. If you want the biggest possible
unsigned integer, its size *will* vary from platform to platform, but
you presented the variation in size as a reason not to use "unsigned
long long".

(And C99 allows extended integer types, so unsigned long long isn't
necessarily the longest unsigned integer type. unsigned long long
could be 64 bits, and uintmax_t could be 128 bits.)

Either you want unsigned long long (whose size will vary, and which
may not exist in a C90 implementation), or you want the largest
unsigned integer type (whose size will vary), or you want an unsigned
type that's exactly 64 bits (which probably exists, but it's not
guaranteed in either C90 or C99). For the second and third cases, a
typedef is reasonable -- and C99's <stdint.h> provides uintmax_t and
uint64_t, respectively. For the first case, if you specifically want
unsigned long long for some reason, a typedef would be silly. Mark,
without going back to the question of what point you were making
upthread, is there anything in this paragraph you disagree with?

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: advantage of using typedefs
    ... Its value is the biggest possible unsigned integer type. ... > Mark McIntyre. ...
    (comp.lang.c)
  • Re: Assuming size_t is unsigned long
    ... No, the Standard only requires that size_t be an unsigned integer type that can represent the size of any object. ... It is not even required to be a standard unsigned integer type. ... "This requirement implicitly restricts size_t to be a synonym for an existing unsigned integer type". ...
    (comp.lang.c)
  • Re: advantage of using typedefs
    ... >the biggest possible unsigned integer to hold offset) then why not declare ... Because then its size would vary from platform to platform, ... c90 implementation it would be an error. ...
    (comp.lang.c)
  • Re: advantage of using typedefs
    ... >>the biggest possible unsigned integer to hold offset) then why not declare ... > Because then its size would vary from platform to platform, ... Yes, but if you want the biggest unsigned integer type, you have to ...
    (comp.lang.c)
  • Re: _Bool bitfields
    ... "Width" of an unsigned integer type, ... _Bool, is defined as the number of value bits, excluding padding. ... And 6.2.6.2p1 says for unsigned integer types ... in a _Bool is a trap representation (because the compiler has a number ...
    (comp.std.c)