Re: Array indexing



Frederick Gotham <fgothamNO@xxxxxxxx> writes:
Keith Thompson:
Once again, the term "integer" refers to a number of distinct types:
(signed|unsigned|plain) char, (signed|unsigned) (short|int|long|long long),
and zero or more extended types. size_t is merely an alias for one of
them.


A conforming implementation can provide an extra integer type, right?
Something like:

__uint128 i = 5;

Yes. I mentioned "zero or more extended types"; __uint128 could be
one of them. See C99 6.2.5.

Can it then go on to make "size_t" an alias of it?

typedef __uint128 size_t;

Yes, but I think there's a DR recommending (but not requiring) that
size_t be no wider than unsigned long. In C90, a portable way to
print a size_t value is:

size_t s;
printf("s = %lu\n", (unsigned long)s);

In C99, this works *unless* the implementation chooses to make size_t
wider than unsigned long. (C99 introduces a new format for size_t,
and another for intmax_t, but any code that uses them will not be
portable to C90 implementations; the point of the recommendation is to
make valid C90 code remain valid in C99 as much as possible.)

If so, the existance of this extra integer type could be transparent
to the programmer, yielding a conformant C implementation. The
important thing about this, however, is that the following
expression could be true:

(size_t)-1 > (long long unsigned)-1

Right, which means it's not entirely transparent.

But practically speaking, unsigned long long is required to be at
least 64 bits, which should be more than big enough for size_t for the
forseeable future. Even assuming a continuation of exponential growth
in memory sizes, 64-bit address spaces will last longer than 32-bit
address spaces did -- and we *might* run into some serious physical
limits before we hit 64 bits.

Note that there are two separate issues here. Keeping size_t no
bigger than unsigned long maintains compatibility with C90 -- but
unsigned long can be as small as 32 bits, and we have memory spaces
bigger than 4 gigabyts already. Keeping size_t bigger than unsigned
long long will be easy until we reach 16 exabytes. (Even where I
work, our biggest archives are just a few petabytes, and they're not
linearly addressible.)

--
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: Extent of the "as-if" rule
    ... > conforming implementation", which is how C90 defines conformance. ... Well, if that's what C90 said, it's been changed in C99. ... satisfy. ...
    (comp.lang.c)
  • Re: Storgae durations
    ... but I've never seen anyone use a C99 ... implementations of C90. ... So the evidence is against you. ... But it isn't the only C compiler on Windows. ...
    (comp.lang.c)
  • Re: Implicit int
    ... implicit int was one of the few benefits C99 brought). ... either a tightening up of the C90 specs, or addition of requested, ... E - the long long int type and library functions ...
    (comp.std.c)
  • Re: Why oh why does this NOT give a compile error?
    ... I guess a lot depends on if the compiler will still accept K&R style code ... A conforming implementation of C99 is required to accept functions without ... that compilers often retained them because they were valid in C90). ... be viewed as, effectively, different languages. ...
    (comp.lang.c)
  • Re: Storgae durations
    ... but I've never seen anyone use a C99 ... implementations of C90. ... If you stick to only conforming C99 ... I know of one other compiler where the author claims C99 ...
    (comp.lang.c)