473,883 Members | 2,621 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 7044
On Thu, 6 Nov 2003 02:26:35 -0600, Randy Howard
<ra**********@F OOmegapathdslBA R.net> wrote:
In article <1e************ **************@ posting.google. com>,
di*********@ya hoo.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?


Why do you think they call him Dim?

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #71
On Wed, 05 Nov 2003 21:47:24 GMT, Keith Thompson <ks*@cts.com> wrote:
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.)

Quite true, but I'm afraid you have a losing battle, especially with
Americans ;-)

In this case, I didn't want to first explain that Roose had made an
error in naming his proposed group, then make my point.

I admit that I have a tendency to be wishy-washy and write "ANSI/ISO",
because hardly anyone I deal with on a daily basis (other than the
fine folks here) uses "ISO" to refer to the standard.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #72
Joona I Palaste wrote:
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.


There's no particular reason why the code should print 42l. It would not be
difficult to come up with an architecture in which it would print 0l
instead. (For example, I16L32, MSB on left.)

--
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 #73
Richard Heathfield <do******@addre ss.co.uk.invali d> scribbled the following:
Joona I Palaste wrote:
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.

There's no particular reason why the code should print 42l. It would not be
difficult to come up with an architecture in which it would print 0l
instead. (For example, I16L32, MSB on left.)


So let me check if I understand this correctly. Suppose you're on an
architecture where sizeof(unsigned long)==4 and sizeof(unsigned int)==
sizeof(int)==2, and it stores multi-byte integers in a big-endian
fashion.
When you write:
unsigned long l=42;
printf("%ul\n", l);
Then the code within printf() is looking at the % sign, and trying to
find out which designator it is. It finds "%u" and treats the "l" that
follows it as normal literal text.
"%u" means "unsigned int" to printf(). So it calls code to fetch
sizeof(unsigned int) bytes from wherever the arguments are stored,
when there really are sizeof(unsigned long) bytes there.
So the argument byte string looks like this: 00 00 00 2A
But printf() is only fetching the first two 00's, and constructing
an integer from them. Well, in big-endian, 00 00 equals 0. So it
prints the 0, and then goes to dutifully print the literal "l",
resulting in an output of:
0l
So this means that printf() will print "0l" for *ANY* unsigned long
that is less than 65536. For any unsigned long that is at least
65536 but less than 131072 it will print "1l" and so on.
If this is so, then there is *all the more reason* for Roose to go
through his code and change "%ul" to "%lu". Not to make us pedants
happy - *TO MAKE HIS CODE WORK RIGHT*! Making us pedants happy is a
free bonus.
If Roose's boss is happy to pay him for writing code that doesn't
work right, then he can be my guest, but I don't want to use that
software.
After all, who knows what strange bugs might happen due to a piece of
software thinking that anything taking up less than 64 kilobytes of
space actually takes up no space at all?

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"He said: 'I'm not Elvis'. Who else but Elvis could have said that?"
- ALF
Nov 13 '05 #74
Randy Howard <ra**********@F OOmegapathdslBA R.net> writes:
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?


To be fair to Roose, he's already acknowledged his incorrect
assumption (that "%ul" is commonly equivalent to "%lu"). I'd say it
was a mistake comparable to writing "%ul" in the first place.

--
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 #75
On 6 Nov 2003 18:46:28 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote:
If Roose's boss is happy to pay him for writing code that doesn't
work right, then he can be my guest,


Hmm,its about time I found out where he works - I have an infinite
quantity of monkeys outside huddled round a really strong cup of tea,
and maybe I could raise a little extra cash by renting them out in
between producing shakespeare plays...
--
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 #76
Mark McIntyre <ma**********@s pamcop.net> wrote in
news:0t******** *************** *********@4ax.c om:
On 6 Nov 2003 18:46:28 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote:
If Roose's boss is happy to pay him for writing code that doesn't
work right, then he can be my guest,


Hmm,its about time I found out where he works - I have an infinite
quantity of monkeys outside huddled round a really strong cup of tea,
and maybe I could raise a little extra cash by renting them out in
between producing shakespeare plays...


I think you might be a bit more successful if you used a really hot cup of
tea... it's the Brownian motion which is important IIRC. :)

Ian Woods
Nov 13 '05 #77
Al Balmer wrote:
On 5 Nov 2003 01:56:01 GMT, sc*@eskimo.com (Steve Summit) wrote:
There is a notion called "speculativ e generality"... This is
basically when you write code that speculates on what you may...
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.


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.


I didn't write the text you quoted -- that was Roose -- but I'm
glad you followed up, because I agree with your point 1000%.

(The trick, of course, that "often" is not "always".
The challenge is therefore -- and *so* many problems boil down
to this! -- to decide when to apply the "generalizi ng a problem
is easier" rule, and when not to.)

Steve Summit
sc*@eskimo.com
Nov 13 '05 #78
[snips]

On Wed, 05 Nov 2003 07:54:11 +0000, Joona I Palaste wrote:
I actually find that statement quite funny. Roose's boss would fire him
if he wrote 100% ANSI C code?


Not surprising in the least.

Boss: "Roose, we're going to roll out the latest thing in advanced gaming
software - multiplayer, strong AI, the works. You're in charge of the UI."

Roose: "Oh, goodie! A new game! Lessee... I could write ANSI C code,
using putchar and fgets and the like for the UI... or I could use OpenGL
or DirectX, provide support for mice, keyboards, multi-function joysticks,
force chairs and the like and give the user an impressive 3D immersion
experience. I wonder which way I should go."

Frankly, if I were his boss and he came up with a 100% ANSI C interface,
I'd fire his butt for sheer gross incompetence.
Nov 13 '05 #79
Kelsey Bjarnason <ke*****@xxnosp amyy.lightspeed .bc.ca> scribbled the following:
[snips]
On Wed, 05 Nov 2003 07:54:11 +0000, Joona I Palaste wrote:
I actually find that statement quite funny. Roose's boss would fire him
if he wrote 100% ANSI C code?

Not surprising in the least. Boss: "Roose, we're going to roll out the latest thing in advanced gaming
software - multiplayer, strong AI, the works. You're in charge of the UI." Roose: "Oh, goodie! A new game! Lessee... I could write ANSI C code,
using putchar and fgets and the like for the UI... or I could use OpenGL
or DirectX, provide support for mice, keyboards, multi-function joysticks,
force chairs and the like and give the user an impressive 3D immersion
experience. I wonder which way I should go." Frankly, if I were his boss and he came up with a 100% ANSI C interface,
I'd fire his butt for sheer gross incompetence.


This depends on how you interpret Roose's words "if he wrote 100%
ANSI C". Your example depicts the interpretation "if he always wrote
100% ANSI C". I interpreted it as "if he ever wrote 100% ANSI C".

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Bad things only happen to scoundrels."
- Moominmamma
Nov 13 '05 #80

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

Similar topics

5
2836
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
5940
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
11665
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
9786
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
11125
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
10734
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...
1
10836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9568
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...
0
5794
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
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4607
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
2
4211
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.