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

Home Posts Topics Members FAQ

Some general questions about C and good practice

Hey! Some questions about C that have been bugging me for a while...

1) Is inline a valid C keyword or not? I was kind of surprised of not
finding it in C, to be honest. My "The C Programming Language" book
doesn't mention it.

2) I understand that C doesn't care about whitespace that much, but why
did they make it impossible to use the minus ('-') char in variable
names? I now have to incorrectly name my "hi-score" variable "hiscore".
:(

3) Is using "const" in C considered good practice? I have had little
need to do so so far thanks to #define.

4) I kind of hate C-like comments. I use C++ comments mostly in my C
programs. Is this evil?

5) I feel kind of naked without bool, but I understand that by the way
computers work, an int holding only 0 or 1 makes the most sense. Or
something. Does it?

PS: I started with C++ and went "back" to C after several years of not
getting anything done thanks to the damn OOP. In C, I'm all creative
again! ^__^

--
http://www.kimmoa.se/

Sep 11 '06
66 3748
On 12 Sep 2006 19:40:17 -0700, in comp.lang.c , "KimmoA"
<ki****@gmail.c omwrote:
>I have now looked it up (yes -- I just HAD to!). Instead of quoting all
you people have said, I'll just write a reply.

In "The C++ Programming Language" (Special Edition), on the bottom of
page 13 (chapter 1, section 1.5), he (Bjarne) says:

"However, good C programs tend to be C++ programs. For example, every
program in [The C Programming Language book], is a C++ program."

This must be where I got it from. Sure... I misquoted him, but it's
been a while since I read it. You can't say that it's entirely false,
though!
Well, its demonstrably false in 2006, some 18 years after the comment
was written. I can provide oodles of well written C that simply won't
compile on a C++ compiler. Just find a programme with memory
allocation.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 13 '06 #51
Keith Thompson wrote:
"Default User" <de***********@ yahoo.comwrites :
jmcgill wrote:
Are you aware that Kernighan and Ritchie used Bjarne's compiler to
validate all their examples? Of course they work.
So? That doesn't make them C++ programs according to the ISO
Standard for that language. They aren't.

It's unlikely that they would be. K&R2 was first published in 1988;
the ISO C++ Standard wasn't published until 1998. The C++ language
changed considerably in those ten years.
C can be expected to compile on a C++ toolchain if it is written in
such a way that it does compile.
Which the examples given weren't.

The examples in K&R2 are, as far as I know, valid C++ *as of the time
they were written*.
That's a good question. What was "C++" at the time? Did C++ of the ARM
allow implicit int declarations? I don't know.

However, the book in question was based on C++ as it was being
standardized. In fact, TC++PL 3rd covers that fact that code such as:

main()
{
return 0;
}
Is NOT valid C++.

Now, my goal is certainly not to bash Dr. Stroustrup. In fact, he once
took time to personally answer an email I had about a question. He has
a fine book, but there's a statement in it (probably inherited from
previous editions) that is somewhat questionable, and which tends to
cause some confusion.
We've doubtlessly given this topic more electrons than it deserves, so
I'll shaddap about it. If others have more to say, I'll read with
interest but leave it at that.


Brian

Sep 13 '06 #52

Default User wrote:
Keith Thompson wrote:
"Default User" <de***********@ yahoo.comwrites :
jmcgill wrote:
>Are you aware that Kernighan and Ritchie used Bjarne's compiler to
>validate all their examples? Of course they work.
>
So? That doesn't make them C++ programs according to the ISO
Standard for that language. They aren't.
It's unlikely that they would be. K&R2 was first published in 1988;
the ISO C++ Standard wasn't published until 1998. The C++ language
changed considerably in those ten years.
>C can be expected to compile on a C++ toolchain if it is written in
>such a way that it does compile.
>
Which the examples given weren't.
The examples in K&R2 are, as far as I know, valid C++ *as of the time
they were written*.

That's a good question. What was "C++" at the time? Did C++ of the ARM
allow implicit int declarations? I don't know.

However, the book in question was based on C++ as it was being
standardized. In fact, TC++PL 3rd covers that fact that code such as:

main()
{
return 0;
}
Is NOT valid C++.
as it is not valid C99. It was valid ARM C++ just as it was valid C89.
>
Now, my goal is certainly not to bash Dr. Stroustrup. In fact, he once
took time to personally answer an email I had about a question. He has
a fine book, but there's a statement in it (probably inherited from
previous editions) that is somewhat questionable, and which tends to
cause some confusion.
I think you should do more homework before casting doubt about other
people's statements.

On the topic of C and C++, I can recommend:

http://www.research.att.com/~bs/bs_faq.html#difference
http://www.research.att.com/~bs/bs_faq.html#merge

and especially the papers referred to there.

-- Bjarne Stroustrup; http://www.research.att.com/~bs

We've doubtlessly given this topic more electrons than it deserves, so
I'll shaddap about it. If others have more to say, I'll read with
interest but leave it at that.


Brian
Sep 14 '06 #53
On 13 Sep 2006 17:25:37 -0700, in comp.lang.c , "bjarne"
<bj****@gmail.c omwrote:
>
as it is not valid C99. It was valid ARM C++ just as it was valid C89.
Thats the point though - your comment in the book related to C and C++
over a decade ago. Its demonstrably incorrect today, but that doesn't
stop people who don't know either language well enough from quoting
you.

I would suggest that you need to qualify the remark in the next
edition of the book, as you have now done on your website.
>On the topic of C and C++, I can recommend:

http://www.research.att.com/~bs/bs_faq.html#difference
http://www.research.att.com/~bs/bs_faq.html#merge
I agree completely with the remarks you've made there, especially the
last paragraph of the first reference.

By the way, in my opinion it is somewhat misleading to say "Well
written C tends to be legal C++ also" and then in a footnote add that
you're talking only of an outdated version. Thats kinda like saying
"every english speaking country is part of the British Empire" and
then in a footnote saying "please note that the above paragraphs apply
to 1700."
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 14 '06 #54
Mark McIntyre said:

<snip>
By the way, in my opinion it is somewhat misleading to say "Well
written C tends to be legal C++ also"
That's not misleading. It's simply false.
and then in a footnote add that
you're talking only of an outdated version. Thats kinda like saying
"every english speaking country is part of the British Empire"
That's not misleading. It's simply true. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 14 '06 #55
On Thu, 14 Sep 2006 10:25:27 +0000, in comp.lang.c , Richard
Heathfield <in*****@invali d.invalidwrote:
>Mark McIntyre said:

<snip>
>By the way, in my opinion it is somewhat misleading to say "Well
written C tends to be legal C++ also"

That's not misleading. It's simply false.
Its not, given the full context and the footnote which I specifically
mentioned. I think you'd be wise to read threads properly.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 14 '06 #56
"bjarne" <bj****@gmail.c omwrote:
Richard Bos wrote:
"KimmoA" <ki****@gmail.c omwrote:
In "The C++ Programming Language" (Special Edition), on the bottom of
page 13 (chapter 1, section 1.5), he (Bjarne) says:
>
"However, good C programs tend to be C++ programs. For example, every
program in [The C Programming Language book], is a C++ program."
>
This must be where I got it from. Sure... I misquoted him, but it's
been a while since I read it. You can't say that it's entirely false,
though!
I not only _can_ say that it's entirely false, I _do_ say that it's
entirely false, and if Bjarne really wrote that, more than a little
dishonest of him.

Careful who you accuse of dishonesty.
My apologies; I did not realise that KimmoA was quoting from an edition
of the book that is so ancient it is useless in a discussion like this.

KimmoA: please don't do that. What Mr. Stroustrup wrote back then may
well have been true for a primitive, pre-any-Standards version of C and
a ditto version of C++, but both languages have advanced since, and it
hasn't been true for over a decade and a half.
I have as much right to talk about C as just about anyone else. I have
the experience (incl. up-to-date experience) with C, and I have made my
contribution to C (check your history: it was major).
I don't intend to disparage your contributions to the history of C or
the current day of C++, but... /hic Rhodos, hic salta/. I try to judge
everybody by what they write and say now, not by their opinions from
fifteen or twenty years ago. I don't even always agree with _myself_
twenty years ago; why should anybody else be different?

Richard
Sep 14 '06 #57
Mark McIntyre said:
On Thu, 14 Sep 2006 10:25:27 +0000, in comp.lang.c , Richard
Heathfield <in*****@invali d.invalidwrote:
>>Mark McIntyre said:

<snip>
>>By the way, in my opinion it is somewhat misleading to say "Well
written C tends to be legal C++ also"

That's not misleading. It's simply false.

Its not, given the full context and the footnote which I specifically
mentioned.
It may not have been false at the time it was written, but it is certainly
false now.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 14 '06 #58
Richard Bos wrote:
My apologies; I did not realise that KimmoA was quoting from an edition
of the book that is so ancient it is useless in a discussion like this.

KimmoA: please don't do that. What Mr. Stroustrup wrote back then may
well have been true for a primitive, pre-any-Standards version of C and
a ditto version of C++, but both languages have advanced since, and it
hasn't been true for over a decade and a half.
The book says "Copyright 2000" and "Reprinted with corrections in May
2003".

--
http://www.kimmoa.se/

Sep 14 '06 #59
On 14 Sep 2006 06:01:13 -0700, in comp.lang.c , "KimmoA"
<ki****@gmail.c omwrote:
>Richard Bos wrote:
>My apologies; I did not realise that KimmoA was quoting from an edition
of the book that is so ancient it is useless in a discussion like this.

KimmoA: please don't do that. What Mr. Stroustrup wrote back then may
well have been true for a primitive, pre-any-Standards version of C and
a ditto version of C++, but both languages have advanced since, and it
hasn't been true for over a decade and a half.

The book says "Copyright 2000" and "Reprinted with corrections in May
2003".
Then its either an erratum which the publishers need to correct, or a
piece of false information.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 14 '06 #60

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

Similar topics

1
2614
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for topics to include in a course on object-orientation that I'm going to conduct. (I will later summarize all the replies and discussion, for the
193
9668
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
19
2211
by: pamelafluente | last post by:
Hi Guys, I am trying to include my little script in my html report. I have done an external JS file which contains it. If you remember, you have helped me to detect if the asp page was present by using ajax. If not present is gracefully stay silent. The problem is now that when the JS is not present (and it can be) MSIE gives a lot of errors and one has to kill it.
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
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...
1
10585
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
10249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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();...
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
2
4007
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.