473,836 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ANSI C compliance

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"

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
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.

What percent of non-trivial programs are completely ANSI C (i.e. they work
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.

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
time to accumulate the knowledge necessary to do so. Thus, in the business
world, it is not considered good practice, since time = money.

There is a field of study you might call "software development", which is
the study of how real teams build real software products. There is a notion
called "speculativ e generality" (from one of Steve McConnell's books I
think, don't
remember which one, see also Martin Fowler). This is basically when you
write code that speculates on what you may need to write need in the future.
Instead of writing code that does exactly what you need to do, you write
something that does more than that, potentially. This is shorthand for
overengineering -- architecting a general system when a specific one will
do.

Writing 100% ANSI C when you are not in a special circumstance (like the one
I listed above) is considered speculative generality. Portability is a
feature of code. Thinking about portability to machine with 9 bit bytes or
2 stacks or no stack or 6 stacks is a waste of time (at least business time,
your personal time is free to be spent however you like), when you have no
forseeable need for it. Because this time could be spent working on
features that actually are required, ones that actually generate money.
Even if you DO have a forseeable need for it, it is considered good practice
to solve _only the problem at hand_. Business requirements are extremely
volatile. Executives are fickle.

An example. Our game started out on PS2. A couple years ago we ported it
to the GameCube and XBox. Did we have completely portable code at first?
No, we wrote a game for PS2. Would it have been easier to port if we had?
Sure, a little. But it wasn't a big deal to fix all the problems as they
came up, as compiled with *real* compilers. And so we did so, in a
straightforward manner.

Do we have standard C code now that we ported it? No. Do we need to? Not
really, the products sold more than 1.5 million copies and generated
millions of dollars in profits.

Now we are investigating porting it to PSP (Playstation portable). Would
it be easier if we have standard C code? Sure, a little. But what if we
never had to port to PSP? Then our effort writing standard C would have
been wasted. What if the PSP compiler has a bad bug that makes it
incompatible with ANSI C? (Not unlikely, since there is only one compiler
for these machines at first, generally).

In software development, *incur the development cost* of a feature *when you
need it*. Not any sooner.

So, the bottom line is, if I was working on making some old nasty code that
works ANSI C compliant, instead of implementing a feature on my schedule
(ANSI C compliance would be laughed off the schedule), my boss would be
PISSED. You don't do that. There is a very real risk of creating bugs in
already working code, which of course is much worse than that code not being
ANSI C.

That said, you should learn the basic rules of the language (to a reasonable
point, there is definitely a point of diminishing returns). Far too many
programmers hack blindly, just trying to shut the compiler warnings up.
(Believe it or not, I am actually the one on the team that adheres most
strictly to standards, e.g. I am the one who hates it when people use enum
as integers, even though that is standard, etc.. My co-workers would have a
good laugh at this, and wonder if this newsgroup is from another planet.)

So, the second bottom line is, that this is C programming in the real world,
which the overwhelming majority of people are interested in doing. As
opposed to whacking off in a newsgroup about their ANSI C knowledge as an
end in itself. That is why CLC is a terrible place to discuss ONLY ANSI C,
as there is already perfectly good place (CLC.moderated) . This is where
people new to C tend to come (as mentioned, alt.comp.lang.l earn-c-c++ is a
joke by its very title), and CLC.moderated would reject many of their posts
as off topic. Since they don't KNOW what standard C is yet, they don't know
what's on-topic.

Good day. If you have a reasoned response to this, I'd be interested in
your opinions.

(But alas, let the flames from the "regulars" begin...)

Roose
Nov 13 '05
100 7035

"Richard Heathfield" <do******@addre ss.co.uk.invali d> wrote in message
news:bo******** **@sparta.btint ernet.com...
Roose wrote:

<snip>
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?


Statistical evidence is worthless in any scientific context. I have a much
better form---anecdotal, the second-best form. I can attest that, after
fifteen years of professional C programming, I started reading this group in
2001. I was a c.l.c. newbie although not a C newbie. I found, and continue
to find, c.l.c. to be a great source of information. Posters here have
corrected some of my misconceptions about C, that have led me to write far
too much code that works by accident. I'm sure c.l.c. has made me a better
programmer, and Richard is one of those (along with too many others to
mention, for fear of missing some) who has facilitated that. Even when I was
a C newbie, I found that getting correct information, even if it
contradicted my then-current understanding, was a benefit. What should scare
newbies away is the sheer volume of disinformation available here, requiring
a brief waiting period for corrections before accepting anything.

<snip>
Nov 13 '05 #61
Alan Balmer <al******@att.n et> writes:
On Wed, 05 Nov 2003 08:57:29 GMT, "Roose" <no****@nospam. nospam>
wrote:
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.


Just to be pedantic, it's more accurate to refer to ISO C rather than
ANSI C. The 1989 ANSI standard was adopted, with some minor editorial
changes, as the 1990 ISO standard. The 1999 standard is
ISO/IEC 9899:1999. (I think it's also officially an ANSI standard;
ANSI is a member if ISO.)

The habit of referring to ANSI C (as opposed to K&R C, the language
defined in K&R 1st edition) originated when the ANSI standard was
being developed in the late 1980s. The term has stuck, but it's no
longer the most accurate one.

--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #62
On Wed, 05 Nov 2003 08:07:48 GMT, in comp.lang.c , "Roose"
<no****@nospam. nospam> wrote:
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 this is not the basic point you've been making at all. Steve is
talking about overengineering , You are claiming that ISO compliance is
a waste of time. ISO Compliance is not overengineering .
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 "overengineerin g" 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,
unfortunatel y.


Hardly. Its subject to real world practicalities and cost benefit.
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.
In your personal opinion. The majority of posters here happen to
disagree. Please refrain from posting your personal opinion as if it
were fact.
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?


Yes. The C implementation should take care of that mess.

IMHO Steve's point was that writing code that specifically needs to
know if a byte is nine bits, is not recommended.
> Even if you DO have a forseeable need for it, it is considered good
> practice to solve _only the problem at hand_.


You keep saying, "is considered". Is considered by *who*?


I would say "is considered" so by capable experts.


Name some. I have seen no evidence to support this laughable claim.
Indeed my own experience (nearly 15 years commercial software
development in banking) is quite the reverse - you have to not only
solve today's problem, but think about future requirements.

If I only solved the problem at hand then today:
- I'd have hard-coded stuff I put in a database instead, thus being
unable to deal with the last-minute requirements change to have three
time bands instead of 2, and altering the threshold from 2cts to 3cts
for the top band.

- I'd have used ESQL to link to the Ingres database used by our
current trading system, instead of isolating the DB element via an
abstraction layer, and being able to handle the expected move to
Oracle that our new TS will use next year.

- I'd have used the API of the brokers directly, instead of using an
(expensive) 3rd party abastraction layer to isolate me from the
individual brokers, thus being forced to recompile my entire app next
week when one of the brokers issues a major upgrade.

By the way, around 75% of my code was ISO (C++ as it happens). The 25%
non-=ISO is nicely segregated in replaceable abstraction layers.

Go figure.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #63
On Wed, 05 Nov 2003 07:43:49 GMT, in comp.lang.c , "Roose"
<no****@nospam. nospam> wrote:
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.
This is a red herring. You don't generally need to do anything to
convert pre-ANSI code to ISO, and if you did need to convert it, then
if you had to do it, you had to.
Also, 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 /am/ a hiring manager and believe me, and candidate who said he
didn't care about standards would be leaving the interview empty
handed. Standards are /vital/ for quality control and maintainability ,
and if your managers disagree, then say 'Hi' to Dilbert for me on your
way past his cubicle, and tell him the garbage man has some neat
device for getting his tie to lie flat.
but my contention is that other features fair better in a
cost/benefit analysis than (often speculative) portablity.
Writing ISO C is not merely about compatibility. Its about writing
safe, stable code that doesn't rely on platform specific tricks.

You should also consider that "porting" includes upgrading to a new
compiler eg MSVC5 to MSVC6, or to a new version of the same OS. For
example Win9x to WinNT to XP, or to a new version of the same hardware
eg IA32 to IA64. You don't think thats important to consider?
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.
Using Oracle instead of Ingres doesn't generate money, it costs a heck
of a lot. But its still worth doing for other reasons.

And besides, writing safe, maintainable code, even for a single
device, saves money. Money saved is money earned. QED.
What percentage of programmers do you think are used to doing it?
(Honestly, I am not sure of the answer). If you were a hiring manager,
wouldn't this unnecessarily limit your pool of applicants if you were to
insist on it?


Alternatively, I hire applicants who have no clue about the actual
language, and think that how it works on (say) solaris is how it works
everywhere. No thanks.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #64
On Wed, 05 Nov 2003 21:47:24 GMT, Keith Thompson <ks*@cts.com> wrote
in comp.lang.c:
Alan Balmer <al******@att.n et> writes:
On Wed, 05 Nov 2003 08:57:29 GMT, "Roose" <no****@nospam. nospam>
wrote:
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.


Just to be pedantic, it's more accurate to refer to ISO C rather than
ANSI C. The 1989 ANSI standard was adopted, with some minor editorial
changes, as the 1990 ISO standard. The 1999 standard is
ISO/IEC 9899:1999. (I think it's also officially an ANSI standard;
ANSI is a member if ISO.)

The habit of referring to ANSI C (as opposed to K&R C, the language
defined in K&R 1st edition) originated when the ANSI standard was
being developed in the late 1980s. The term has stuck, but it's no
longer the most accurate one.


There was even a seven month period when 9899:1999 was the ISO/IEC
standard but not the ANSI one, from October 1999 to May 2000.

But this is one point hardly worth the pedantry. There is literally
no chance of eradicating the phrase "ANSI C" from common use.

--
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.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #65
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in message news:<bo******* ***@sparta.btin ternet.com>...
te*********@BUS ThotmailE.Rcom wrote:
I find it fascinating that Richard begins his defense of one lie with
another:


It's unfortunate that you choose the word "lie" to describe a poor choice of
wording, but c'est la vie.

"you will never see a regular contributor /begin/ a thread with
an off-topic article."

Of course, he does try to explain away this one with his lame 'never say
never' comment...but if he really meant this, he would have said
something like:

You will almost never see a regular contributor begin a thread with
an off-topic article.


I will cheerfully accept the alternative wording, but do you have an actual
example of an OT comp.lang.c thread started by a regular contributor?
Various regulars have, of course, started totally off-topic threads in
the past...


Example, please.


<http://groups.google.c om/groups?threadm= 3C59AAE4.10203C 26%40yahoo.com>
Nov 13 '05 #66
Dim St Thomas wrote:
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in message
news:<bo******* ***@sparta.btin ternet.com>...
te*********@BUS ThotmailE.Rcom wrote:
> Various regulars have, of course, started totally off-topic threads in
> the past...


Example, please.


<http://groups.google.c om/groups?threadm= 3C59AAE4.10203C 26%40yahoo.com>


Yes, that's an excellent example (albeit perhaps not a very tactful one). In
fact, it perfectly illustrates that comp.lang.c is not only a newsgroup,
but also a *community*, with a community's conventions, dynamics, mores,
customs, and also a reasonable amount of friendship and compassion.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #67
In article <nS************ @newssvr14.news .prodigy.com>,
no****@nospam.n ospam says...
Again I claim if I went through my code looking for %ul and replacing it
with %lu, it would not be looked upon highly.


OMG. You really are pretending to be a C programmer, aren't you?

--
Randy Howard _o
2reply remove FOOBAR \<,
_______________ _______()/ ()_____________ _______________ _______________ ___
SCO Spam-magnet: po********@sco. com
Nov 13 '05 #68
In article <1e************ **************@ posting.google. com>,
di*********@yah oo.com says...
<http://groups.google.c om/groups?threadm= 3C59AAE4.10203C 26%40yahoo.com>


Well, aren't you the sick little troll? Surely you could have found
something more valuable to your argument?

--
Randy Howard _o
2reply remove FOOBAR \<,
_______________ _______()/ ()_____________ _______________ _______________ ___
SCO Spam-magnet: po********@sco. com
Nov 13 '05 #69
Randy Howard <ra**********@f oomegapathdslba r.net> scribbled the following:
In article <nS************ @newssvr14.news .prodigy.com>,
no****@nospam.n ospam says...
Again I claim if I went through my code looking for %ul and replacing it
with %lu, it would not be looked upon highly.
OMG. You really are pretending to be a C programmer, aren't you?


Well, it *could* be that with the programs he's paid to write, "42" and
"42l" are considered the same output.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"C++ looks like line noise."
- Fred L. Baube III
Nov 13 '05 #70

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2834
by: Acacia | last post by:
a) Does the C++ language never change? I was recommended to upgrade my MSVC v1.5 to a newer compiler - yet I thought that ANSI C++ was a standardised language and never changed - so why would i need to upgrade my compiler? More features? b) How good is C++? Would it be worth learning for a computer, and possibly programming, enthusiast? Has it got a long life ahead of it or is it likely to die out soon replaced by newer languages?
3
5936
by: Jack | last post by:
Hi I am just trying to get a feel for what oracle SQL syntax there is that would not be covered at all in anyway from a functionality perspective in the standard ANSI SQL.. Any input is appreciated.. Thank you, Jack
83
11645
by: sunny | last post by:
Hi All What is C99 Standard is all about. is it portable, i mean i saw -std=C99 option in GCC but there is no such thing in VC++.? which one is better ANSI C / C99? can i know the major difference between C99 & ANSI C standards?
0
9665
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10835
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7785
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6976
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5818
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4447
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.