473,836 Members | 1,586 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 3749
On Thu, 14 Sep 2006 12:13:56 +0000, in comp.lang.c , Richard
Heathfield <in*****@invali d.invalidwrote:
>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.
Yes, which is what I said, and indeed made exceptionally clear in the
quote that you gratuitously snipped. Whats your point exactly? You're
behaving oddly.
--
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 #61
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.
His "special edition" is the hardbound 3rd edition, ISBN0201700735, and
hardly "ancient."

Still,

C(x): x is a valid C program.
P(x): x is a valid C++ program.
\exists C(x) \in P(x), x \in {valid programs}

It doesn't mean anything in terms of a language specification, but
Stroustrup was observing that C++ can be, in some cases, a superset of C.
Sep 14 '06 #62
[Attribs tersificated]

Mark McIntyre said:
Richard Heathfield wrote:
>>Mark McIntyre said:
>>Richard Heathfield wrote:
<snip>
>>>>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.

Yes, which is what I said,
RH: "It's simply false."
MM: "Its not..."
RH: "It is"
MM: "Yes, which is what I said..."

Hmmm.
and indeed made exceptionally clear in the
quote that you gratuitously snipped.
Hardly gratuitous. We both know the context.
Whats your point exactly?
Just beyond your grasp, it appears. :-(
You're behaving oddly.
That's certainly an opinion. In /my/ opinion, however, I am behaving evenly.

--
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 #63
bjarne wrote:
Argh. My intent as I said in the previous message was to drop this, but
I'd better defend a bit.
Default User wrote:
main()
{
return 0;
}
Is NOT valid C++.

as it is not valid C99. It was valid ARM C++ just as it was valid C89.
But the book didn't say that. It said every program in K&R2 *is* a
valid C++ program, not that they were when the book the came out. Two
different statements.
I think you should do more homework before casting doubt about other
people's statements.
I don't see that much is needed. The statement in the early section of
the book quoted here isn't accurate, although when the topic it covered
explicitly in later chapters it's of course correct.

There is a difference between C++ then and now. It's accurate to say,
"The programs were valid C++" but it's not to say (in a book about ISO
Standard C++), "The programs are valid C++".

This is not a huge deal, although it obviously caused some confusion
for at least one contributor here. I can't imagine me ever putting
together a textbook, let alone getting every single line and statement
crystal clean and unambiguous.

Again, and it bears repeating, my goal is NOT to insult, disparage, or
otherwise cast aspersions on Dr. Stroustrup over a single line in a 900
page text.


Brian (hope we can let her rest now)
Sep 14 '06 #64
jmcgill <jm*****@email. arizona.eduwrit es:
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.

His "special edition" is the hardbound 3rd edition, ISBN0201700735, and
hardly "ancient."

Still,

C(x): x is a valid C program.
P(x): x is a valid C++ program.
\exists C(x) \in P(x), x \in {valid programs}

It doesn't mean anything in terms of a language specification, but
Stroustrup was observing that C++ can be, in some cases, a superset of C.
But that is not what he said; there were further qualifiers in there
than mere validity and existence. There was a term "well-written"
that appears to have been left out of your formal statement entirely,
which is the crux of the matter.

Nobody disputes that there is a common subset of C and C++, in which
code can be written that it syntactically and semantically valid and
defined according to both languages. The dispute is in the part you
left out, which is that *well-written* valid C is likely to be valid
C++ as well. As can be demonstrated by a trivial counterexample, this
is not true.

Charlton

Sep 14 '06 #65
On Thu, 14 Sep 2006 15:29:12 +0000, in comp.lang.c , Richard
Heathfield <in*****@invali d.invalidwrote:
>RH: "It's simply false."
MM: "Its not..."
RH: "It is"
MM: "Yes, which is what I said..."

Hmmm.
Have you mistaken me (or even yourself) for Jacob? I can see little
other reason for you deliberately and apparently maliciously not only
misquoting me but also making up quotes.
>Whats your point exactly?

Just beyond your grasp, it appears. :-(
And being offensive is hardly grown up. Still, while we're at it,
bugger off and stop being so silly.
--
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 #66
Mark McIntyre said:
On Thu, 14 Sep 2006 15:29:12 +0000, in comp.lang.c , Richard
Heathfield <in*****@invali d.invalidwrote:
>>RH: "It's simply false."
MM: "Its not..."
RH: "It is"
MM: "Yes, which is what I said..."

Hmmm.

Have you mistaken me (or even yourself) for Jacob?
No.
I can see little
other reason for you deliberately and apparently maliciously not only
misquoting me but also making up quotes.
No, sir; I have not misquoted you, or at least I have certainly not
/deliberately/ misquoted you, let alone /maliciously/ misquoted you, and I
have not made up any quotes whatsoever. I have elided some of what you've
said in an attempt to make your self-contradiction more obvious, but it's
implicit in what you said originally, so I'm not misrepresenting you.

I'm not sure why you're reacting so hostilely, given that my initial
response was very light-hearted, but I think it would be a good idea to
calm down a little.

--
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 #67

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
9668
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
10843
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
10254
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
9371
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
7790
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
6978
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
5648
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
5825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4015
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.