ANSI C compliance

J

Joona I Palaste

Mark McIntyre said:
On Tue, 04 Nov 2003 05:40:15 GMT, in comp.lang.c , "Roose"
This is a stupid statement. In the Real World, which you seem not to
inhabit, computer programs interact with their surroundings. This
interaction is by definition Implementation Specific, and consequently
not part of the C language. Naturally there are parts of what we all
write that are not C. So what?

I actually find that statement quite funny. Roose's boss would fire him
if he wrote 100% ANSI C code? I.e. Roose's boss is *forcing* him to be
non-portable? Out of practical reasons, or out of principle?
If it's the latter, then I can imagine some quite funny situations:

Roose's boss: "Roose, I just found out that you wrote this program:
#include <stdio.h>
int main(void) {
unsigned long l=0;
while (getchar()!=EOF) l++;
printf("%ul\n", l);
return 0;
}
to count the number of bytes in a file. Don't you see it's 100%
ANSI C code?"
Roose: "Oh, sorry, boss. I'll change that to void main(void)."
Roose's boss: "Thanks."

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates
 
R

Richard Heathfield

I actually find that statement quite funny. Roose's boss would fire him
if he wrote 100% ANSI C code? I.e. Roose's boss is *forcing* him to be
non-portable? Out of practical reasons, or out of principle?
If it's the latter, then I can imagine some quite funny situations:

Roose's boss: "Roose, I just found out that you wrote this program:
#include <stdio.h>
int main(void) {
unsigned long l=0;
while (getchar()!=EOF) l++;
printf("%ul\n", l);
return 0;
}
to count the number of bytes in a file. Don't you see it's 100%
ANSI C code?"
Roose: "Oh, sorry, boss. I'll change that to void main(void)."
Roose's boss: "Thanks."

Roose's correct response would be "No, boss, sorry to contradict you but
look at the printf! See?" I'm passing in an unsigned long, but the format
specifier is %ul instead of %lu; I reckon that's got to be an
implementation-defined at best, and quite possibly a genuine undefined!"
 
R

Roose

If you stop to think about it, this is a pretty meaningless
statement. Take out the words "truly standard C as valued by the
regulars in this newsgroup" and replace them by any positive
attribute of code you can think of:

Writing functional code is time-consuming if you're not experienced.
Writing maintainable code is time-consuming if you're not experienced.
Writing compact code is time-consuming if you're not experienced.
Writing efficient code is time-consuming if you're not experienced.
Writing correct code is time-consuming if you're not experienced.

Are all of these, then, "not considered good practice" in the
business world?

As I said in the previous post, in many environments, it doesn't produce
benefits that are proportional to the time it takes, or the cost of hiring
people who can do it with no additional time involved.

The other positives are of course worth their cost in all situations. Or at
least, they can be evaluated by the same metric... e.g. if I spend time
optimizing this code, what real benefit do I get? Does it matter?
And this is a very tricky set of ideas to think properly about.
Yes, sometimes when you overengineer something you're wasting
resources which could be better spent elsewhere, no question.

Yes, thanks for acknowledging at least a basic point from me, which many
others have been loathe to do.
But other times, a certain level of overengineering is not just
good practice, it's mandatory. In the real world, for example,
it's not "overengineering" to build a structure to withstand a
severe storm. To build a house that can withstand exactly the
weather conditions you're experiencing today, but which falls
down during the first rain or windstorm, would be folly.

Well, of course this is subject to individual programmer discretion,
unfortunately. If only there were an objective set of criteria to determine
if something is overengineered. Personally though, most people think my
code is a little overengineered, and I think theirs is underengineered. But
it falls within the domain of "reasonable", where reasonable developers can
agree, where as strict ANSI C as promoted by this newsgroup sometimes does
not.
I don't think anyone here is advocating always writing code which
tries to be portable to machines with 9 bit bytes. (Personally,
I don't even know how to.) Your other examples are even more
absurd, since no C program (let alone a portable one) can even
tell how many stacks there might be.

Well, the claim here has been that if you write strict ANSI C, then it will
be portable to a machine with 9 bit bytes or no stack, with no additional
effort. No?
> Writing 100% ANSI C when you are not in a special circumstance

You keep saying, "is considered". Is considered by *who*?
By you? By the managers at the software companies that foist upon
the world laughably insecure, virus-infested operating systems,
and word processors that perform functions that no sane person
would require of them and ("Ford added savagely") go beep to tell
you when they've done it? They can have their opinions of what
"is considered" good practice, thank you; me, I think I'll use my own.

My first statement is what we're disputing, which you have given good
arguments for. My second, I would say "is considered" so by capable
experts.
Programmers who let executives tell them how to write their code
are jointly responsible for the unmaintainable failures they go on
to create.

I agree, but in a different context. As I said in the previous post, the
lack of high-level design contributes much more to unmaintainability than
the failure to write ANSI C. This is a huge problem where I work. The
schedule pressures force hacks upon hacks, rather than rethinking the
original design to meet new requirements. ANSI C is not even on the table.

Roose
 
J

Joona I Palaste

Roose's correct response would be "No, boss, sorry to contradict you but
look at the printf! See?" I'm passing in an unsigned long, but the format
specifier is %ul instead of %lu; I reckon that's got to be an
implementation-defined at best, and quite possibly a genuine undefined!"

Damn. s/ul/lu/ then. I hope I got my point across nonetheless. I *knew*
someone would make a point like that. Writing 99.999999999999999999999%
ANSI C code is easy, all you really have to do (once you're a good
programmer) is avoid anything that smells of hardware, or OS specifics.
But writing *100%* ANSI C code is surprisingly tricky.
 
R

Roose

Joona I Palaste said:
Damn. s/ul/lu/ then. I hope I got my point across nonetheless. I *knew*
someone would make a point like that. Writing 99.999999999999999999999%
ANSI C code is easy, all you really have to do (once you're a good
programmer) is avoid anything that smells of hardware, or OS specifics.
But writing *100%* ANSI C code is surprisingly tricky.

Yes, thank you for providing a great example of what I'm taking about. To
all those responded with reasoned responses, this is what I claim is not
reasonable from a business perspective. Again I claim if I went through my
code looking for %ul and replacing it with %lu, it would not be looked upon
highly.

Roose
 
R

Roose

Jack Klein said:
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.

Not sure what the point of the fortran example is exactly, but I'm talking
about people who, at the expense of answering anyone's _real_ question,
ignore anything not related strictly to ANSI C, and instead inundate them
with irrelevant details about ANSI C. Again my claim is that -- regardless
of whether they are right to come here -- a lot of newbies do, and get
turned off to the C language. Yes, I've already heard all the responses
about reading the FAQ and such, and I maintain my position regardless.
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.

I do that too, and I suspect many others do. Which is why the extremely
narrow focus on ANSI C limits the utility of this newsgroup for your average
C programmer. As I said, in the game I'm working is portable across PS2,
GameCube, and Xbox, but it is decidely not ANSI C. We use non-standard
extensions like 0-length arrays and such.

I don't know for sure how common this extension is, but I think it is
extremely common, since it seems to be a case that would just "fall out" of
a compiler, requiring no extra code. If not, replace it with something else
that is not standard but nearly universal. (If there is no such thing,
suppose there is such a thing).

Then I claim that using such a thing is fine business practice, its ANSI
compliance notwithstanding. (Oh let the flames begin, again...) Contrary
to what seems to be espoused on this newsgroup, someone who uses such an
extension, is not ignorant or stupid or contributing to the
unmaintainability of his codebase.

If an extension provides a reasonable benefit, and is reasonably common,
then it in effect a useful part of a _de facto standard_ (*gasp* : ) ). I
suggest that one might use such an extension and get the benefit, while
incurring the cost of removing it when business dictates that you port to a
platform that doesn't support it (which may or may not ever happen).
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.

Sounds cool.
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%.

OK, point taken. I will discuss the proportions of code in a project that
is ANSI C from now on.
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.

See my responses to Steve Summit... if you were a hiring manager, would you
limit your applicant pool in such a way, when it is clear that people who
are not completely familiar with strict ANSI C would be capable of meeting
the business objectives?
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.

I don't see how this follows. Because I don't place high importance on ANSI
C does not mean I advocate "shoddy guesses and half-baked efforts". As I
have written elsewhere, I write for specific platforms, and choose to spend
my time on more important considerations like program architecture, rather
than the line-by-line details of individual pieces of code.
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".

These arguments don't mean much to me. As I said, time spent in one place
is not spent in another. I claim that, in many typical business situations,
when you are writing for specific platforms, ANSI C is not worth the time.
The time is much better spent learning your domain, whether it is airliner
hardware or medical equipment. Also, as I said, there much more important
general software development considerations, like writing unit tests,
improving your build process, training engineers in design principles, etc.

I am very doubtful of the methodology of preventing bugs a priori by using
ANSI C, as contrasted with spending the resources on proper QA, which many
organizations fail to do. Indeed, I would suspect that you asked
programmers of airliners and medical equipment, they would say their
_quality bottleneck_ is in QA and unit testing, rather than in ANSI C
conformance.

So where do you think the bottleneck typically is?
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.
Agreed.

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.

I agree with many of your points in this argument, but let me also mention
all the newbies who get jumped on by the regulars. This is not a few
people -- pretty much in any screenful of threads, I see it happening.

But let me say that this is not as interesting a discussion as the first
point about whether the value of ANSI C compliance is extremely dependent on
business objectives, and not an end in itself. I acknowledge your points,
and suggest that there should be a group called comp.lang.ansi-c or
whatever, but I will admit with the attitude here, that is not likely to
happen. ANSI C is a limited part of C in the real world, and thus the name
comp.lang.c is misleading, which is (part of the reason) why there are so
many off-topic posts here. And I already suggested that there is already a
perfectly good group, CLC.moderated, that has a fine mechanism for
_enforcing_ topicality -- a much more efficient mechanism than regular
flamewars.

Roose
 
K

Keith Thompson

Roose said:
Yes, thank you for providing a great example of what I'm taking about. To
all those responded with reasoned responses, this is what I claim is not
reasonable from a business perspective. Again I claim if I went through my
code looking for %ul and replacing it with %lu, it would not be looked upon
highly.

Why not? Don't you believe in fixing bugs?

Are you assuming that "%ul" happens to work as a format for unsigned
long on most implementations, and converting it to the more
standard-compliant "%lu" would be a waste of time?

In fact, "%ul\n" is a valid printf format; the "%u" converts an
unsigned int, and the "l" is a literal lower case letter L.
The statement

printf("%ul\n", l);

if l is equal to 42, will print "42l" followed by a newline. The bug
might even be missed in testing if it's misread as 421.

I'm just making a guess about what you were assuming; if I was
mistaken, can you clarify your point?
 
J

Joona I Palaste

You have missed my point. You said "My boss would fire me if I wrote
100% ANSI C code". I asked if this is because he hates 100% ANSI C
code in itself, or he hates his workers trying to perfect their code
into 100% ANSI C.
I gave an example of the former, while your reply concerns the latter.
Which is it?
Why not? Don't you believe in fixing bugs?
Are you assuming that "%ul" happens to work as a format for unsigned
long on most implementations, and converting it to the more
standard-compliant "%lu" would be a waste of time?
In fact, "%ul\n" is a valid printf format; the "%u" converts an
unsigned int, and the "l" is a literal lower case letter L.
The statement
printf("%ul\n", l);
if l is equal to 42, will print "42l" followed by a newline. The bug
might even be missed in testing if it's misread as 421.
I'm just making a guess about what you were assuming; if I was
mistaken, can you clarify your point?

If Roose's boss thinks there's no difference between "42l" and "42" (as
output strings), then good for him, but I don't want to work in that
company.
 
J

James Hu

Yes, thank you for providing a great example of what I'm taking about. To
all those responded with reasoned responses, this is what I claim is not
reasonable from a business perspective. Again I claim if I went through my
code looking for %ul and replacing it with %lu, it would not be looked upon
highly.

You mean your employer would accept the letter ell attached to the ends
of unsigned output?

BTW, the above is not a personal attack. It is an example of the kind
of pedantry that is practiced in comp.lang.c.

Actually, I would like to apologize if my "Princess Bride" parody
offended you (or anyone else reading the newsgroup). Half of it was
tongue-in-cheek, but perhaps it didn't come across that way. It may
have inadvertently fanned the flames, which I did not mean to do. The
serious point of the message was that perhaps you needed to spend some
more time reading through the kinds of posts in the newsgroup before
contributing. The humourous point (which may have been lost on you and
others due to not getting the reference) was that you were behaving like
a Humperdink.

The kind of battle you are waging now has been waged many times here in
the past. I imagine the old-timers on this newsgroup are quite frankly
tired of arguing the point yet again.

(http://groups.google.com/groups?q=topicality+group:comp.lang.c)

To me, at least, you are simply pointing out the obvious when you say
that most useful programs are not "100% ANSI C", and quite frankly
that point is a yawner. We already know that. It doesn't mean you
shouldn't try to write the code that is platform independent to be as
close to ANSI C as you know how. Steve Summit has already elucidated
the benefits. This newsgroup is great resource for learning how to do
it better.

As to beginners who are learning how to code in C, it is my belief that
it is very important that they understand Standard C before they learn
platform specific programming. This is because a programming language
is supposed to provide an abstraction over a platform, and to maintain
encapsulation, the beginner should be shielded from the platform.
This allows the beginner to apply the newly obtained C programming
knowledge on any platform.

When fresh graduates who are well-grounded in Standard C go off into the
real world to become neo-professional C programmers, their knowledge
will be applicable to any C programming job, modulo the platform
specific interfaces they need to know for the particular position they
are applying.

If you use a single particular platform (such as an x86 based PC)
to provide platform specific examples as a way of grounding the
abstractions, this creates a dangerous situation where students will
likely generalize with insufficient information. This can cause them to
go into the workforce woefully misinformed and unprepared, and you end
up having to retrain them both in C programming and in the platform
specific interfaces of their job.

Or worse, they can't obtain or hold a job.

Common problems from over generalizations:
* assumptions about the size of the int type.
* assumptions about the behavior of modifying a variable and reading
its value between two sequence points.
* assumptions about the order of evaluation of function parameters.

By advocating that programmers should simply hack away on their systems
paying little to no heed to portability (and pay the price of porting
later), you only further propogate the harm that generalizing with
insufficient information can do. When the code is later ported,
you also get the bonus problems of (1) less maintainable code, and
(2) introducing quirky problems that are not easily reproducible or
identifiable due to incorrect assumptions about what the code means.
(Both of the numbered problems above are of course avoided if of the
port effort also includes scheduled time to carefully paying attention
to standards and actually clean up the portability issues.)

Or worse, the buggy code gets shipped because the defect could not be
isolated, and the bug actually causes tangible harm to the consumer of
the software system.

Coding in Standard C will not alleviate all coding issues. But,
following the discipline helps train the programmer to think critically
about the program, and critical thinking is usually a good thing to
practice when the goal is a working software system.

In practical terms:

* do not write C code that invokes unspecified and undefined behaviors.
* be cognizant of utilizing implementation-defined and locale-specific
behaviors, and of utilizing common C language extensions. Isolate
them, and document their use so that future porting efforts are
reduced.

But in this newsgroup, I aim to provide solutions that do not require
implementation-defined behaviors. If there is no such solution, I may
discuss an implementation-defined solution, but I will also point out
the non-topicality of the thread and ask the OP to followup someplace
more appropriate.

-- James
 
P

pete

Richard said:
specifier is %ul instead of %lu;

Since becoming aware of my having made that mistake more than once,
I always call them "long unsigned"
instead of "unsigned long".
 
P

pete

Jack Klein wrote:
There happen to be quite a few compilers for embedded systems which
come under the category of free-standing implementations. It is not
uncommon for such implementations to specify that the user-written
start-up function signature should be "void main()", generally "void
main(void)", as there are never anything like command line arguments
in such environments.

This newsgroup tends to assume "hosted" unless otherwise stated.
In free-standing implementations,
the main function, can be called anything.
I've worked on embedded, where the main function was called
"start_main_"
 
A

Alan Balmer

Generalization does not always take extra time. In fact, I have found
that generalizing a problem often leads to a solution which is not
only extensible, but easier and cleaner to implement in the first
place.
 
A

Alan Balmer

I am very doubtful of the methodology of preventing bugs a priori by using
ANSI C, as contrasted with spending the resources on proper QA, which many
organizations fail to do. Indeed, I would suspect that you asked
programmers of airliners and medical equipment, they would say their
_quality bottleneck_ is in QA and unit testing, rather than in ANSI C
conformance.

Sorry, wrong. Quality comes in the production of the product, not the
testing. I've not programmed for airliners, but I have programmed for
medical equipment, and I have done a great deal of programming for
mission- and life-critical process control. There's an excellent
chance that you are within reach of a plastic product produced in part
with my software, and to my knowledge, a PVC reactor hasn't exploded
for years.

It's a common saying that quality cannot be legislated by QA or tested
into a product by QC. Testing can show the presence of errors, but
cannot show the absence of errors.

ANSI/ISO C is not the be-all and end-all of quality programming, but
it's a valuable aid. While most programs in my world must use some
facilities that are outside the scope of the standard, it's no
problem, and no extra work, to write proper code for the 95% which can
be standard C. In fact, most of that other 5% is standardized as well,
conforming to POSIX, which has relatively high portability. I really
don't understand your contention that writing standard C where
possible costs more. In fact, for products with a reasonably long
lifetime, it's cheaper. In your limited world of game programming,
perhaps you just replace obsolete code. Most of us don't have that
luxury, and have to consider maintenance as part of the life-cycle
cost.

This is anecdotal, but I have done a great deal of C maintenance
programming, ever since the standard was approved (and written much
code we called C before that :). and while doing that I have made a
lot of legacy code standard-conforming. Nearly every time I've done
that, I've uncovered bugs which would have been caught by a pedantic
compiler if the program had been written in standard C originally.
(Aside - it's amazing how customers will live with bugs for years and
how ingeniously they sometimes work around them. We've got 'em
trained.)

Bottom line is that this newsgroup discusses Standard C. That's what
we do here. It doesn't mean there aren't other things to discuss, it
just means that other things should be discussed in other places. If
you try that, you'll find than many of the folks here you've accused
of being narrow-minded and not knowing about the outside world also
participate in those other groups.

Have you looked at comp.programming, for example? They discuss much
wider issues than comp.lang.c.
 
A

Alan Balmer

and suggest that there should be a group called comp.lang.ansi-c or
whatever,

Nope. C *is* ANSI-C. The standard is the very definition of C To me,
comp.lang means just that - discussions about the *language.* Not its
applications, not extensions to it, not libraries for it or algorithms
coded in it, but the language itself and its proper use. No confusion
there.

I think what you want is a group named comp.programming.c, and that
might actually be a good idea, though I wonder if the traffic would
justify subsetting comp.programming. You could work toward creating
such a group, and in the meantime, participate in its parent,
comp.programming (where you'll also find some of the c.l.c regulars,
being less pedantic ;-)

What you are *not* going to be able to do is hijack this newsgroup and
redefine it as what you want it to be. It is what it is.
 
S

Sheldon Simms

If Roose's boss thinks there's no difference between "42l" and "42" (as
output strings), then good for him, but I don't want to work in that
company.

No you misunderstand. Roose's boss wants bugs. That's the problem.
If Roose bothered to write correct code, then the development group
wouldn't fulfill their bug quota, and without a full bug quota the
testers wouldn't have anything do to, and the company might have to
release a product on time.
 
R

Roose

Why not? Don't you believe in fixing bugs?
Are you assuming that "%ul" happens to work as a format for unsigned
long on most implementations, and converting it to the more
standard-compliant "%lu" would be a waste of time?

Yes, that's what I was assuming, and I stand corrected. You mean you guys
don't test your code before posting it? : ) I will look for another
example of such a thing.

Roose
 
M

Mark Gordon

Let me thank you first for making a reasoned argument. My time is not
unlimited, so let me ignore the vast majority of responses and focus
on the ones such as this that rely logical argument -- AND acknowledge
the existence of life outside the newsgroup.



OK, I think the real point was lost somewhere there, but my contention
is that ANSI C being "better" is dependent on the situation, and not
an absolute fact.

Such instances are few and far between in my experience. Equally, my
experience is that writing code to be as portable as possible can often
save you time *BEFORE* you reach the deadline.

A REAL example:
Writing a significant chunk of embedded code. Since the code was as
portable as possible I ended up porting it to a Silicon Graphics
workstation and debugging it there because there were far better tools
available including the ability to read some aircraft attitude data and
the digitised video and overlay a line of the video indicating where my
software believed the horizon was. This saved a significant amount of
time on that particular project.
Right, let me suggest that if you were a manager -- with limited
budget as always -- that training programmers to write ANSI C and
converting old code to ANSI C would often be on your cut list. Also,

Converting pre-ANSI code to ISO C is not required to write any
modifications in ISO C. By making such changes as you deal with the
relevant parts of the code you can gradually ease the burden of
maintenance without a significant bad effect on your immediate
timescales and budgets. I know this through personal experience just as
I know that gradually making the change can expose problems that only
occasionally cause the application to misbehave and allow you to fix
them.
if you were a hiring manager, I would suggest that it is often the
case that one programmer who does not "care" about ANSI C would often
suit your purposes better than another that does.

I would expect and good C programmer to be able to cope with pre-ANSI
code on a legacy project. I know this because I *AM* working on such a
project. I also know that the head of my SW department would far prefer
people who understand and care about standards compliant software than
those who don't care about it.
Also correct, but my contention is that other features fair better in
a cost/benefit analysis than (often speculative) portablity. Other
features cost money as well, but they also generate money. Writing
ANSI C for a single device does not, in general, generate any money.

If you know how to write portable code then my experience is that in
most cases it does not cost more than writing non-portable software.
I think this decision is made fairly often in the business world. But
if you have experience that demonstrates otherwise, I'd be interested
to hear about it.

See my comments above. All are based on real personal experience in the
defence and commercial worlds.
What percentage of programmers do you think are used to doing it?
(Honestly, I am not sure of the answer).

Anyone in the defence industry will have their code peer reviewed so it
only takes a few people for the word to slowly spread. Outside the
defence industry things are different.

Personally I learnt most of my C from K&R2 referring to the manuals for
the compiler when I needed to do something HW specific and *knowing*
that the HW specific stuff I was doing was specific to the
implementation as it was documented as such. This does not mean that I
did not introduce non-portable constructs by mistake in code I
considered to be portable, but it did bring things a long way towards
it.
If you were a hiring
manager, wouldn't this unnecessarily limit your pool of applicants if
you were to insist on it?

As with everything, when recruiting you weigh the cost/benefit. If
someone is good enough and prepared to learn but does not know enough
about portable coding one might consider them just as one would reject
someone who could only write simple portable programs and was not
willing to learn.
I would say that the last 4 virtues you mention are _absolute_
virtues, while the former is a business decision. I completely agree
that we should strive to do better -- but our time is limited, and
focusing on one thing comes at the expense of others. I would much
rather (and my boss would much rather me) learn a new rendering
technique, rather than study the ANSI C standard. I would much rather
write a unit test than make my code ANSI compliant.

Making your code ISO compliant can remove bugs you are not aware of and
your compiler can probably provide a lot of help in doing this and if
not you may be able to run it through gcc with maximal warnings to see
the issues. So you should at least try to see how close you are and
whether there is anything immediately critical that you can resolve as
*part* of your testing. Potentially you look through the optional
warnings s your compiler can generate and enable ones that are most
likely to show up real problems, such as -Wsequence-point on gcc.

You don't have to spend a lot of time/money in one go, 5 minutes per
day would be a start and could remove unexplained crashes that you
can't track down.
I'm not saying you're wrong, but rather I'm objecting to the extremely
narrow focus demonstrated in this newsgroup.

This group is about programming in C and not about implementation
specifics. If you don't like it then use another group. There are plenty
of places for discussing the specifics of any given implementation
where you will find a lot more expertise on that specific
implementation.
The posts come at the
expense of the larger question -- in recent threads the larger
questions being answering an interview question (so as to demonstrate
knowledge), and also helping a newbie learn C.

A lot of helpful information was posted and people I know who *have*
been interviewers would have liked many of the answers.
Many people have
already stated that newbies are welcomed here. In that case, it would
be prudent to address them in a manner that they can understand,
rather than turning them off to the C language with nitpicking.

Accurate answers are given (and inaccurate ones corrected) and if
someone asks for further explanation it will be provided. Many people
*try* to pitch their answers at the apparent level of knowledge of the
person asking the question whilst still doing this.
I
would also contend that learning strict ANSI C is not the first step
for a beginning C programmer. There is enough challenge in getting a
working program together.

It is far easier to get a working program together if you set the
warning level on your compiler as high as possible and try to understand
and *resolve* the warnings (not just cast them away) than if you don't
do this. Such a method also leads you naturally in to producing ISO C
programs.

Also, trying to use libraries outside of those provided by the C
standard means you have *more* to learn and so makes the job harder.
However, we (or I at least) don't object to people new to see using the
simpler external libraries, it is just that we will direct them else
where for help with those libraries.
Completely agree. However, I would say that the line-by-line
deficiencies in code (e.g. non-ANSI code) are completely and utterly
overshadowed by the lack of design knowledge by the average
programmer.

When I started my career I was not expected to do the design. Instead I
would be presented with the design (if there was any significant
complexity) and be asked to code it. Thus I was exposed to good design
at any given level before I was expected to do it, and when doing design
work or coding others would look at my work and provide help and advise
as required. IMHO this is a correct way to tackle the issue and allows
the learning of both good coding in ISO C and good design at the same
time.

I have also been in the position of mentoring fresh graduates and I
would gradually build up the complexity of what they were required to do
making sure they were heading in the right direction before letting them
loose.
Attack the worst of the ills first. And the one that has
the most effect on maintainability and understandability of code is
the fact that your average codebase is filled with faulty
abstractions, or, sadly, none at all.

However, those ills are for other groups such as comp.unix.programmer,
although people do point out design flaws when reviewing code that is
posted here in order to move people in the right direction. Asking for
such help here is off topic, but providing it *whilst* dealing with the
C issues is considered acceptable based on what I've seen.
 
R

Richard Heathfield

Roose said:
Yes, that's what I was assuming, and I stand corrected.

Could you tell us about even one implementation on which %ul works as a
format for unsigned long? Or does your "I stand corrected" mean that you no
longer believe that /any/ implementations do this?

I ask merely for information.
You mean you guys
don't test your code before posting it? : ) I will look for another
example of such a thing.

If you find a bug in code posted here, and no correction for that bug has
been posted, please do post a correction. You may be surprised by the
reaction. In fact, I urge you to look for bugs in code that I myself have
posted, partly for your own satisfaction, but also so that you can see the
kind of reaction that one can expect when posting a correction in this
newsgroup.

Part of the immense value of this newsgroup is the extraordinary attention
to detail displayed by its nit-pickers.
 
R

Richard Heathfield

Roose wrote:

Not sure what the point of the fortran example is exactly, but I'm talking
about people who, at the expense of answering anyone's _real_ question,
ignore anything not related strictly to ANSI C, and instead inundate them
with irrelevant details about ANSI C.

The details are far from irrelevant in a C newsgroup. They might well be
considered irrelevant in a group such as comp.programming or sci.crypt.
Again my claim is that --
regardless of whether they are right to come here -- a lot of newbies do,
and get
turned off to the C language.

Doubtless you have independent and compelling statistical evidence to
support this assertion. Where is it?

if you were a hiring manager, would
you limit your applicant pool in such a way, when it is clear that people
who are not completely familiar with strict ANSI C would be capable of
meeting the business objectives?

I would consider hiring a person not familiar with C (which is my term for
what you call "strict ANSI C"), provided that they made up for this
deficiency in other relevant areas and provided that they were able to
demonstrate willingness to learn C.

I am very doubtful of the methodology of preventing bugs a priori by using
ANSI C, as contrasted with spending the resources on proper QA, which many
organizations fail to do.

Correct use of the C language sure beats the hell out of its incorrect use
when it comes to preventing bugs. And correct use of C is pretty much what
we discuss here.

ANSI C is a limited part of C in the real world,

Sure, if by "C in the real world" you mean "C together with a bunch of
libraries and extensions", but it's the core, the vital part of the
language, and it's essential to understand that core if one is to be an
effective C programmer.
and thus the name comp.lang.c is misleading,

comp - computing
lang - language
C - C

I don't see anything misleading here. The key point is that C is defined by
an international standard, not by the misunderstandings and
platform-specific experiences of anyone who happens to drop into clc one
cold November evening when there's nothing good on television.


<snip>
 
T

Thomas Matthews

Mark said:
Such instances are few and far between in my experience. Equally, my
experience is that writing code to be as portable as possible can often
save you time *BEFORE* you reach the deadline.

A REAL example:
Writing a significant chunk of embedded code. Since the code was as
portable as possible I ended up porting it to a Silicon Graphics
workstation and debugging it there because there were far better tools
available including the ability to read some aircraft attitude data and
the digitised video and overlay a line of the video indicating where my
software believed the horizon was. This saved a significant amount of
time on that particular project.

In support, another Real World example:
I was working on code for an embedded laser printer. The task was
page control (sequencing, and resource aquisition). The code was
based on data input. Since resources were tight (i.e. 5 people shared
the same printer to work on), writing in ANSI C code allowed me to
debug the code on the PC using a debugger to single step through
the code (and setting appropriate variables). This debugging
process was often faster than trying to debug using the proprietary
debugger after waiting many hours for free time on a printer.

One note: Many of the real world programs have code that is platform
dependent. However, those portions can be confined to their own
modules and replaced by "stubs" for other platforms. In my case,
I used some stubs for platform specific functionality.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top