C considered harmful

Henry Spencer henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org
Thu Dec 4 22:44:19 UTC 2003


On Thu, 4 Dec 2003, John Macdonald wrote:
> ... *and then convince the language that it is allowed to use
> the converted result.  Often, languages that try to
> prevent errors do not provide a way to cheat (i.e.
> compose a "pointer" by hand).

The ones that are intended for systems programming generally do provide a
way to do it, although it may be encapsulated in a special "low-level
operations" library rather than being something you can casually do in one
line of source code.

(That encapsulation is probably a good thing.  C's big problem is not that
it can do bizarre stuff, but that the compiler can't tell whether that's
what you really wanted.  You *can* write a bounds-checking C compiler --
there is nothing in the standard C language that prevents it -- but
because it's so hard to tell what the programmer is up to, such an
implementation has to use worst-case strategies that impose heavy run-time
overheads.)

System calls generally are invoked via library routines anyway.  If worst
comes to worst, those routines can be written in assembler, so they can
cheat as required.  (That's how things were done in the original Unix C
implementation on the pdp11, in fact, because the system-call calling
conventions had been designed for use from assembler and weren't a good
match to C.)

                                                          Henry Spencer
                                                       henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list