The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Re: Maximum Array Sizes in 16 bit C
@ 2024-09-18 23:51 Douglas McIlroy
  2024-09-18 23:57 ` Henry Bent
  0 siblings, 1 reply; 17+ messages in thread
From: Douglas McIlroy @ 2024-09-18 23:51 UTC (permalink / raw)
  To: TUHS main list, henry.r.bent

[-- Attachment #1: Type: text/plain, Size: 360 bytes --]

> The array size} limit that I found through trial and error is (2^15)-1.
> Declaring an array that is [larger] results in an error of "Constant
required",

On its face, it states that anything bigger cannot be an integer constant,
which is reasonable because that's the largest (signed) integer value. Does
that version of C support unsigned constants?

Doug

[-- Attachment #2: Type: text/html, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread
* [TUHS] Re: Maximum Array Sizes in 16 bit C
@ 2024-09-20 15:24 Douglas McIlroy
  0 siblings, 0 replies; 17+ messages in thread
From: Douglas McIlroy @ 2024-09-20 15:24 UTC (permalink / raw)
  To: TUHS main list

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

Apropos of the virtue of negative subscripts.

> by pointing into the middle of another data structure you've created a
data aliasing situation

Not if all references are relative to the offset pointer. The following
example is silly,  but I recently used exactly this trick to simplify
calculations on a first-quadrant (x,y) grid by supplying "out-of-bounds"
zeroes at (x,-2), (x,-1) and (-1,y). It was much cleaner to access the
zeroes like ordinary elements than to provide special code to handle the
boundary conditions.

/* Fill an N-element array with Fibonacci numbers, f(i), where 0<=i<N.
   The recursion accesses a zero "out of bounds" at i=-1 */

const int N = 100;

int base[N+1];
#define fib(i) base[(i)+1]

void fill() {
    int i;
    fib(0) = 1;
    for(i=1; i<N; i++)
        fib(i) = fib(i-2) + fib(i-1);
}

Doug

[-- Attachment #2: Type: text/html, Size: 1204 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-09-20 22:19 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18 23:51 [TUHS] Re: Maximum Array Sizes in 16 bit C Douglas McIlroy
2024-09-18 23:57 ` Henry Bent
2024-09-19 13:13   ` Rich Salz
2024-09-20 13:33     ` Paul Winalski
2024-09-20 15:07       ` Dave Horsfall
2024-09-20 15:30         ` Larry McVoy
2024-09-20 15:56         ` Stuff Received
2024-09-20 16:14         ` Dan Cross
2024-09-20 17:11         ` G. Branden Robinson
2024-09-20 20:16           ` Bakul Shah via TUHS
2024-09-20 20:58             ` Warner Losh
2024-09-20 21:18               ` Rob Pike
2024-09-20 22:04               ` Bakul Shah via TUHS
2024-09-20 22:19               ` G. Branden Robinson
2024-09-20 15:26       ` Rich Salz
2024-09-20 19:40     ` Leah Neukirchen
2024-09-20 15:24 Douglas McIlroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).