Re: advantage of using typedefs



Mark McIntyre <markmcintyre@xxxxxxxxxxx> writes:
> On 28 Jan 2006 00:50:55 -0800, in comp.lang.c ,
> "junky_fellow@xxxxxxxxxxx" <junky_fellow@xxxxxxxxxxx> wrote:
>
> (concerning typdef'ing)
>
>>Thanx for your reply, Emmanuel. 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;
>
> Because then its size would vary from platform to platform, and on a
> c90 implementation it would be an error. Some implementations spell
> "long long" as "__int64", others don't support it at all etc etc.
>
>>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.

If you want a type whose size *doesn't* vary, you want
something like uint64_t (and if you need this in C90, see
<http://www.lysator.liu.se/c/q8/>). (I think most C90 implementations
these days provide 64-bit integer types under some name.)

BTW, C99 defines uintmax_t for precisely this purpose.

--
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
    ... >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
    ... but the size of long long varies from platform to ... >>Yes, but if you want the biggest unsigned integer type, you have to ... But if this is the case (ie we need the biggest possible unsigned ... necessarily the longest unsigned integer type. ...
    (comp.lang.c)
  • Re: enum type int or unsigned int?
    ... integer type, ... mention of char seems pretty redundant to me, though, since it's ... 'signed integer type' or 'unsigned integer type'. ... enumeration type can be compatible with an enumeration type, ...
    (comp.lang.c)
  • Re: Is UINT_MAX required to be 2^n-1?
    ... > Chris Croughton wrote: ... 'representation' which finds the relevant sections). ... integer type is a subrange of the corresponding unsigned integer type, ...
    (comp.std.c)
  • Re: Playing around with byte order
    ... code computes at runtime the byte-order of the unsigned integer, ... most people put all their standard header inclusions together, ... unsigned char GetByte(const unsigned * const pu, ... unsigned readLSBplus_offset(long unsigned number, size_t offset); ...
    (comp.lang.c)