Out-of-bounds pointers

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Oct 11 16:26:01 AEST 1989


In article <976 at crdos1.crd.ge.COM> davidsen at crdos1.UUCP (bill davidsen) writes:
>	Ptr = &ShortVect[-30000];

There are so many implementation assumptions required to make this work
that it really cannot be considered sane portable programming practice.

>I submit that this is neither sloppy programming or
>meaningless, and that it is "not illegal" by K&R 1st Ed.

I disagree on both counts.

>  That's certainly keeping the discussion on a high technical plane.

Matters of surprise, unreliability, etc. are hardly very technical.

>  Please identify the machines in question and quantify the saving.

No.  I'll conduct my argument on my own terms, thank you very much.

>  Prevailing practice means what it says, that before compilers were
>modified to make it illegal such code would work on most machines, such
>as Sun, Vax, PC, Cray, PDP-11, etc. I think that fairly represents at
>least 80% of the machines and users running pre-ANSI C.

Nobody "modified compilers to make it illegal".  The Standard simply
makes it clearer than it may have previously been that you're asking
for trouble when you write such code.  On some implementations it will
work all the time, on others it will work some of the time, and on
others it will never work.  That's due to variations in computer
architecture, and to require that such dubious practice be made to
work in ALL cases as you seem to expect it to would burden some
implementations for insufficient reason.  (Plus it would be
exceedingly difficult to specify such behavior in the Standard; we
had a hard enough time getting the wording for last+1 right.)



More information about the Comp.std.c mailing list