From: Ralph Corderoy <ralph@inputplus.co.uk>
To: Douglas McIlroy <douglas.mcilroy@dartmouth.edu>
Cc: COFF <coff@tuhs.org>
Subject: [COFF] Re: Maximum Array Sizes in 16 bit C
Date: Mon, 23 Sep 2024 13:12:21 +0100 [thread overview]
Message-ID: <20240923121221.94883207D9@orac.inputplus.co.uk> (raw)
In-Reply-To: <CAKH6PiU4rqt1npr8eXcDAZQHvXq+RZauDGzLmG2hM+gnTEQwOA@mail.gmail.com>
Hi Doug,
> int base[N][N+2];
> #define binom(n,i) base[n][(i)+1]
Thanks for the interesting prompt. I've been having a think about it
along the lines of sliding the ints in memory.
Have you considered having a single dimension of ints and then accessing
them as if a two-dimensional array, with [0][0] being offset?
$ cat offset.c
#include <stdio.h>
#define N 4 // N×N values
#define L 3 // L columns of 0 to the left
#define U 2 // U columns of 0 upwards
int main()
{
char m[(U + N) * (L + N)] =
"abcdefg"
"hijklmn"
"opq+BCD" // The '+' is a[0][0].
"rstEFGH"
"uvwIJKL"
"xyzMNOP";
char (*a)[L + N] = (char (*)[L + N])&m[U * (L + N) + L];
for (int y = -U; y < N; y++) {
if (!y)
putchar('\n');
for (int x = -L; x < N; x++) {
if (!x)
putchar(' ');
putchar(a[y][x]); // y,x relative to ‘+’
}
putchar('\n');
}
}
$ gcc -Wall -Wextra -Werror offset.c
$ ./a.out
abc defg
hij klmn
opq +BCD
rst EFGH
uvw IJKL
xyz MNOP
$
--
Cheers, Ralph.
next prev parent reply other threads:[~2024-09-23 12:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-21 0:22 [COFF] Re: [TUHS] " Douglas McIlroy
2024-09-23 12:12 ` Ralph Corderoy [this message]
2024-09-24 16:44 ` Dan Cross
[not found] <CAKH6PiWvuxfa_ek=L=n=mgovFk_ms37u6F2N1qcMLs6RXLRWvA@mail.gmail.com>
[not found] ` <CAEdTPBfPcmZybb0CVLxhzB-nLTQb3aohWV-o_8ZqQJXmUc4yPA@mail.gmail.com>
[not found] ` <CAFH29to4_DFdx=U=ZRVY_HE0YGR8tw00Ya4PJhLGR4Z1UMF6_g@mail.gmail.com>
[not found] ` <CABH=_VR6=wJdgCLArHLd8q3N+BGj=5m16X4WBkB+o5XksbSsbw@mail.gmail.com>
[not found] ` <11d46ab4-b90c-83fe-131a-ee399eebf342@horsfall.org>
[not found] ` <20240920171126.vgtl23xwj37kardb@illithid>
[not found] ` <69643008-F7FE-4AC7-8519-B45E4C1CEA66@iitbombay.org>
[not found] ` <CANCZdfpy9AsOfE+mvt+DkBYXiwfENLjscMHCT0nnU7WGz54T_Q@mail.gmail.com>
[not found] ` <0B54746F-504A-40E0-AFFD-4486167FBAD5@iitbombay.org>
2024-09-29 0:17 ` [COFF] " Aron Insinga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240923121221.94883207D9@orac.inputplus.co.uk \
--to=ralph@inputplus.co.uk \
--cc=coff@tuhs.org \
--cc=douglas.mcilroy@dartmouth.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).