Re: pointers?
- From: anton@xxxxxxxxxxxxxxxxxxxxxxxxxx (Anton Ertl)
- Date: Tue, 21 Mar 2006 16:33:48 GMT
Andrew Haley <andrew29@xxxxxxxxxxxxxxxxxxxxxxx> writes:
Anton Ertl <anton@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Andrew Haley <andrew29@xxxxxxxxxxxxxxxxxxxxxxx> writes:
Take
this, for another example:
int a[N];
int b[N];
prdiff_t delta = b-a;
foo (a, delta);
It's fairly easy to see what's going on here, but bury it beneath a
few layers of abstraction and it becomes much harder.
The only problem I see here is with the unscaling performed by C on
pointer subtraction (this might lose bits unless the ints are
naturally aligned); this problem can exist even with very simple
compilers.
Ok, thinking some more, I'm taking another guess: The compiler has a
bug in its liveness analysis, does not see that b is used, and
eliminates it as a dead variable.
Right. Well, not a bug IMO, but yes, that's what I'm talking about.
Let's see: Foo is called with delta as parameter, therefore delat is
alive. To compute delta, b is used, therefore b is alive. Yet the
compiler "optimizes" b away, therefore the compiler has a bug.
When someone reports this as a bug, the first thing the compiler
writer does is looking around for non-standardness, finds it, and
considers himself absolved of any responsibility to compile the
program as the programmer intended.
Well, what you're suggesting here amounts to an extension of the
programming language.
Actually, the comment was inspired by a discussion
(<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15242#c6> ff.) about a
case that involved a real extension. Gcc had a bug, and since the
program was not ANSI C, a defender of gcc's behaviour just stopped
thinking about what the program should mean and declared it ambiguous,
although the actual meaning was pretty straightforward to see. I
guess that if gcc had had a bug that involved one of the examples from
the gcc manual, his reaction would have been the same, at least at
first.
Is an implementor responsible not only for
implementing the language, but also all of a programmer's
misunderstandings of it?
If, as in this case, many programmers don't know about some
restriction of the standard, and the compiler does not warn about it,
and implements the behaviour expected by the programmer when not
optimizing, and relying on the restriction leads to hard-to-find bugs,
then a high-quality compiler will not rely on the restriction unless
the programmer asks for it (in gcc maybe with -ansi).
Maybe the compiler should support the "faulty" model that most
programmers understand, rather than using a more complex model that
few understand.
Well, that would require the previously faulty model to be defined in
such a way that it could actually be implemented.
Well, in the examples we were discussing here, the "faulty" model is
that of a flat address space. And it obviously can be implemented by
just disabling this kind of "optimization".
Also, you're assuming that programmers understand the /same/ faulty
model!
We were talking about a flat address space model that you claimed was
"faulty". Are you claiming there are different flat address space
models?
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.complang.tuwien.ac.at/forth/ansforth/forth200x.html
.
- References:
- pointers?
- From: Colin MacIntyre
- Re: pointers?
- From: Bernd Paysan
- Re: pointers?
- From: Andrew Haley
- Re: pointers?
- From: Anton Ertl
- Re: pointers?
- From: Andrew Haley
- Re: pointers?
- From: Anton Ertl
- Re: pointers?
- From: Andrew Haley
- Re: pointers?
- From: Anton Ertl
- Re: pointers?
- From: Andrew Haley
- pointers?
- Prev by Date: Re: a roguelike for Forth
- Next by Date: Re: Is Forth for real?
- Previous by thread: Re: pointers?
- Next by thread: Re: pointers?
- Index(es):
Relevant Pages
|