.
Given a large region of memory with no \0 byte, it seems the keep
pointer could overflow and wrap, of the ptrdiff of (keep - hast) could
be unrepresentable. Either possibility is bad. How to guard against
the badness?
In the code below, can anyone produce
printf ("what is the meaning of this\n");
I can only get
printf ("my pointer wrapped around\n");
[snip most code lines, except a representative few:]
omega = data;
omega += SSIZE_MAX - 2;
diff (alpha, ++omega);
.... (above line appears 7 times or so)
if (omega == alpha) {... }
As Seebach notes in his reply, "If you go outside the boundaries of an
object, you have invoked undefined behavior. [...] Don't go outside
the boundaries of an object. Then there is no badness." [1]
The question relevant in c.l.c isn't so much "can anyone produce"
certain behavior, as "can anyone produce, portably and in accord
with C standards", to which the answer is no, due to the irretrievably
undefined behavior of the program. That said, when I run the program
on my x86_64 Linux system with gcc, it gives the same result you got.
As a practical matter in a program like this, include a couple more
lines -- eg
printf ("SSIZE_MAX is %lx\n", SSIZE_MAX);
in main, and
printf ("a %8p o %8p ", alpha, omega);
before the printf in diff, to make it more obvious what happens.
[1] Re "Then there is no badness", I presume Seebach references
only the little microcosm in which such a program compiles and
runs, rather than the world as a whole. But I could be wrong,
perhaps he sees defined behavior as a fix for all the problems
of the world.