It's different viewpoints...
Posted May 30, 2011 17:46 UTC (Mon) by anton
In reply to: It's different viewpoints...
Parent article: What Every C Programmer Should Know About Undefined Behavior #3/3
Who writes *(foo *)&thing_of_type_bar and doesn't think 'that is ugly and risky, there must be a better way'?
I write such code. It's ugly, true. It did not use to be risky until
some compiler writers made it so; on the contrary, it worked as I
expect it to on all targets suppored by gcc-2.x (and the example of
mpr22 about code that's not 64-bit clean is a red herring; that's a
portability bug that does not work with -O0 or gcc-2.x -O, either, so
it has nothing to do with the present discussion).
But code like this one of the reasons for using C rather than, say,
Java. C is supposed to be a low-level language, or a portable
assembler; even Chris Lattner claims that "the designers of C wanted
it to be an extremely efficient low-level programming language". This
is one of the things I want to do when I choose a low-level language.
One of my students implemented Postscript in C#; it was interesting to
see what was not possible (or practical) in that language and how
inefficient the workarounds were. If we were to write in the common
subset of C and C#/Java, as the defenders of misbehaviour in gcc and
clang suggest, we would be similarly inefficient, and the
"optimizations" that these language restrictions enable won't be able
to make up for that inefficiency by far.
Maybe your programs are not affected in this way, unlike some of my
programs, but then you don't need a low-level language and could just
as well use a higher-level language.
to post comments)