This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Serious code generation/optimisation bug (I think)


Zoltán Kócsi wrote:

I don't mean to complain, but I happen to work with embedded systems. I program them in C, or at least in a language that uses the syntactic
elements of C.

Yes, and that is an important distinction. If you program in C, you should program in C (and know the language).

While it might not be a C program and is utter nonsense
from a linguistic view, in the embedded world dereferencing a NULL
pointer is often legal and actually unavoidable.

The trouble is that this is not defined in C, so if you need to do something reliably that is not supported by the language you have chosen to program in, you should use a machine language insertion, that's the only reliable way to get what you want.

Once you start trying to go outside what the language you are
using defines, you are asking for big trouble.


MOn every one of those chips it is
legal to dereference a NULL pointer as long as you have the notion of
a pointer being an address of something. I've been programming in C for
almost 30 years and I neglectfully not followed the language's semantic
development, maybe that's why I am confused to think that C is a
low-level, system programming language and not a highly abstract
language where a "pointer" is actually some sort of a complex
reference to an object that may or may not actually occupy memory.

People who program in C under the illusion that it is a simply defined low level language where they don't have to worry about the formal abstraction, are working indeed under an illusion.

Assuming, of course, that the notion of "memory" is still a valid one,
in the old sense of collection of addressable data units residing in a
so-called address space. I think the existence of keywords referring to
aliasing is an indication to that, but I am not sure any more.

In that caveman mental domain of mine I would assume that if I
dereference a NULL pointer and on the given environment it is a no-no,
then something nasty is going to happen; an exception is raised on a
micro or I get a sig 11 message on my terminal or the whole gizmo just
resets out of the blue. On the other hand, if the given architecture
treats address 0 as address 0, then it should just fetch whatever value
is at 0 and merrily chug along. In fact, I would assume that since on
every CPU I've ever used the address space included 0, one could do
this:

Your attitude is reasonable in the abstract, but unfortunately the semantics of C does not correspond to this abstraction.

So, pretty please, when the compiler detects that a language resembling
to, but not really C is used and removes assumedly (albeit unprovenly)
superfluos chunks of code to purify the misguided programmer's intent,
could it please at least send a warning?

That's a reasonable request, although for technical questions it is often harder than you might imagine to give such warnings.

Just to indicate to those
idiots who are at least aware of their dumbness and thus use -W -Wall
-Wextra -Werror in their CFLAGS that it is now time to purchase the
latest C standard and brush up with the recent changes with regards to
the interpretation semantics of such things as addresses, arrays,
pointers and so on.

If you do, you will be shocked :-)



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]