Re: [PATCH] C undefined behavior fix

From: Paul Mackerras (
Date: Wed Jan 02 2002 - 21:51:33 EST

Momchil Velikov writes:

> Where do you see changes in pointer arithmetic ? Or in the "memory
> model" (whatever that means) ?

The C standard says that doing pointer arithmetic is only valid within
the bounds of a particular array of objects; do anything outside that
and the behaviour is "undefined". The reason it says that is that it
is trying to lay down the rules that will ensure that your program
will work on a PDP-10 or on a 286 with 64kB segments, as well as on
reasonable architectures (such as those that Linux runs on).

Now the claim is that RELOC is bad because it adds an offset to a
pointer, and the offset is usually around 0xc0000000, and thus we are
"violating" the C standard. Thus we are being told that someday this
will break and cause a lot of grief. My contention is that this will
only break if a pointer becomes something other than a simple address
and pointer arithmetic becomes something other than simple 2's
complement addition, subtraction, etc. If that happens then C will
have become useless for implementing a kernel, IMHO.

> I'd dare to state that _very_ few people would join the quest for
> writing the kernel in something other than C.

The kernel is already written in a dialect of C that breaks some of
the rules in the C standard. Look at virt_to_phys, phys_to_virt,
__pa, __va, etc. for a start. I don't see that changing.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Mon Jan 07 2002 - 21:00:20 EST