Just to make a tangential point here, in case anyone new to C doesn't
understand what all these flame wars are about.
Shorthand title: "My boss would fire me if I wrote 100% ANSI C code"
I personally write few completely 100% strictly conforming programs on
the job. When the opportunity presents itself, I do, which occurs a
surprisingly large fraction of the time.
We are discussing whether this newsgroup should focus on 100% ANSI C or
simply topics related to the C language in the real world. There is a C
Your "real world" is most certainly not the same as my "real world".
One of the world's most used C compilers, gcc, has a command line
switch to compile FORTRAN. That's a "real world" use of a C compiler.
But it has nothing to do with the C language, which has one and only
one definition.
standard which is defined by an international committee. People who write
compilers refer to this in order to make sure their compilers follow the
standard -- that they actually compile C. However, they also add extensions
to the C language to make your life easier, and of course there are bugs in
the compilers and such.
So for various reasons, C you write which runs and works as expected on one
platform might not work on another platform. The C standard is there to
alleviate this -- to decide which compiler is wrong if they differ in
behavior.
Amazingly enough, I manage to write code that is non-standard
conforming that works as expected on multiple platforms. Because I
know enough about the C language and its implementation-defined
aspects.
For a current product I designed a communications protocol for an
internal CAN network. And I wrote code to implement that protocol.
That code is most certainly not 100% strictly conforming standard C.
But that somewhat non-standard code compiles and runs correctly on
four different processor types that interface to that bus:
1. An 8-bit big-endian microcontroller (8051 architecture). Chars
have 8 bits and plain char is signed.
2. A 16-bit big-endian microcontroller (Motorola HC11 architecture).
Chars have 8 bits and plain char is signed.
3. A 16/32 bit little endian DSP (Texas Instruments 28xx
architecture). Chars have 16 bits and plain char is signed.
4. A 32 bit little-endian RISC processor (ARM9). Chars have 8 bits
and plain char is unsigned.
Now I won't say there wasn't a little debugging involved, but I knew
when I wrote it that the entire code for protocol, including parse
tables, parameter packing and unpacking from CAN packet octet streams,
and all the rest, would work on all four of these architectures when I
wrote it.
The routine that converts between individual octets and 8, 16, and 32
bit signed or unsigned variables runs unchanged on all four platforms,
even the DSP which actually can't address memory in less than 16 bit
chunks.
What percent of non-trivial programs are completely ANSI C (i.e. they work
You entirely miss the point. What percentage of all trivial and
non-trivial C program, no matter how platform specific they are, could
be written in completely standard C? I doubt if you would ever find a
non-trivial program where this figure is less than 50%. Even in many
large programs with loads of extensions, if is frequently above 90%.
as intended on all platforms for which you have an ANSI C compiler, modulo
compiler bugs)? I would suspect somewhere near 0%, just like about 0% of
non-trivial programs are completely bug free. Even taking this into
account, I would suspect less than 5% of non-trivial C programs written are
intended to be, or actually are, standard C. It simply isn't necessary
engineering practice, although there are certainly exceptions. For example,
one job I once interviewed for was writing standard ANSI C implementions of
licensed technology, that were meant to be ported (by hand) to assembly on
DSPs by the licensees. That is, the idea was to write something for other
people to read and compile, not something to actually go in a real product.
Again you have it wrong. The question is not what fraction of
programs are nothing but 100% strictly conforming C. The question is
the average part of all programs that is, or could be, standard C.
And that fraction is very high indeed.
Now, on to my point. Writing truly standard C as valued by the "regulars"
in this newsgroup is time-consuming if you're not experienced. And it takes
One who is not sufficiently experienced in writing C programs properly
should not be employed to do so, except perhaps as an apprentice, and
should not claim to be a professional C programmer.
time to accumulate the knowledge necessary to do so. Thus, in the business
world, it is not considered good practice, since time = money.
Yes, the biggest problem with software in general is not C or C++ or
Pascal or Visual Basic or any other programming language. It is
programmers who believe like you, that business is served by shoddy
guesses and half-baked efforts.
Would you want to fly on an airliner engineered by aviation engineers
who had their attitude about learning their discipline and doing
design work that you express toward writing software?
Would you want to be operated on by a surgeon who decided that
performing quality surgery is too time-consuming to learn, and
couldn't be bothered to take the time to accumulate the knowledge
necessary, because "it is not considered good practice, since time =
money".
There is a field of study you might call "software development", which is
There is a field of study that is called "software engineering", and
there is extensive research, much of it headed up by the US government
funded Software Engineering Institute at Carnegie-Melon University.
Engineering is a discipline, and there is sadly far too little
discipline in software development. The field is too new, the growth
too fast.
[snip]
This is very far afield from the main thrust of your post, however.
You think there is value in diluting comp.lang.c to throw in
discussions about anything anyone is trying to do with any C compiler
anywhere. I, and many of other the regulars, disagree.
It makes no difference whether you are writing C for a PIC
microcontroller, a Cray supercomputer, a game console, or an
"ordinary" Windows or Macintosh PC. A large percentage of the code
should be or at least could be perfectly standard legal C. And aside
from platform-specific issues that have nothing to do with the topic
of this group, that is the C language, a certain percentage of the
problems in even the most platform-specific program will be C language
issues.
Usenet groups that can't stay focused on a topic die. Our "sister"
group comp.lang.c++ nearly had that experience about five years ago,
where swarms of MFC and Windows specific newbies caused many of the
most knowledgeable regulars to leave. Fortunately, a group of
determined regulars turned back the tide barely in time, and
comp.lang.c++ is a valuable resource for C++ programmers today.
In point of fact, some of the regulars in comp.lang.c are among the
most knowledgeable C programmers in the world, at least among those
who chose to offer aid and advice publicly for free. Destroy the
topicality of the group, and you drive away that expertise.
So if you want to discuss platform-specific aspects of your code, take
it to the appropriate platform-specific support group. But when you
have a truly complex C language issue, be glad this group is here for
you to post it, because if it is really difficult you have a better
chance of correct help here than anywhere else on Earth.
And keeping this group on-topic is the best way to ensure that this
resource remains available.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq