473,654 Members | 3,028 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 #1
66 3685
KimmoA wrote:
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.
It is valid in C99 but not in C89.
>
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".
Because the compiler wouldn't be able to tell
whether hi-score subtracts score from hi or is
the name of a single variable. If it's any consolation
to you hi-score is also incorrectly named.
3) Is using "const" in C considered good practice? I have had little
need to do so so far thanks to #define.
It is good practice for declaring constant objects. If for
example a function is not supposed to modify an
argument , then you use const. #define wouldn't help in
this case.
>
4) I kind of hate C-like comments. I use C++ comments mostly in my C
programs. Is this evil?
C comments are beautiful ; C++ comments are ugly.
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?
Makes sense as opposed to what ?

Sep 11 '06 #2
Spiros Bousbouras wrote:
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.

It is valid in C99 but not in C89.
Hmm... I guess I'm following C99, then. I'm not explictly telling my
compiler (MinGW) about this, though.
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".

Because the compiler wouldn't be able to tell
whether hi-score subtracts score from hi or is
the name of a single variable.
Yeah, but why not require spaces in between for that operation? You
should code with "air"... :(

Of course, nothing can or will be changed by now, but it's still nice
to hear the reasoning. Was C designed with obfuscation contests in
mind? ;)
If it's any consolation to you hi-score is also incorrectly named.
Do you mean that it should say "high-score"?
C comments are beautiful ; C++ comments are ugly.
I find C as a whole to be rather beautiful. At least relatively.
However, the comments are just crappy IMO. Just like in CSS, you have
to end them, and they use two different chars. /* This doesn't
encourage me to comment! */

At least C++-like comments are two of the same char and don't need to
be ended!

// Aaah! I like commenting stuff this way!

I guess that this, again, has to do with the nature of C and the almost
total lack of care about whitespace.

At least it (C99?) accepts C++-style comments.
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?

Makes sense as opposed to what ?
As opposed to having a special data type called "bool". If nothing
else, it helps telling me what's a "boolean" and what's a "high number"
variable.

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

Sep 11 '06 #3
In article <11************ **********@e3g2 000cwe.googlegr oups.com>,
KimmoA <ki****@gmail.c omwrote:
>Hey! Some questions about C that have been bugging me for a while...
>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".
:(
hi_score

(Note, though, that there are various restrictions having to do
with starting identifiers with underscores, or ending identifiers
with _t or a few other prefixes that I don't recall offhand.)
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Sep 11 '06 #4
KimmoA wrote:
Spiros Bousbouras wrote:
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.
It is valid in C99 but not in C89.

Hmm... I guess I'm following C99, then. I'm not explictly telling my
compiler (MinGW) about this, though.
Or it could be that your compiler is implementing
some C99 extensions bur not all of them.
>
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".
Because the compiler wouldn't be able to tell
whether hi-score subtracts score from hi or is
the name of a single variable.

Yeah, but why not require spaces in between for that operation? You
should code with "air"... :(

Of course, nothing can or will be changed by now, but it's still nice
to hear the reasoning. Was C designed with obfuscation contests in
mind? ;)
I was only guessing about the reasoning. Extra space
would make the code longer and back in those days
they didn't have a lot of memory.
>
If it's any consolation to you hi-score is also incorrectly named.

Do you mean that it should say "high-score"?
Yes.
>
C comments are beautiful ; C++ comments are ugly.

I find C as a whole to be rather beautiful. At least relatively.
However, the comments are just crappy IMO. Just like in CSS, you have
to end them, and they use two different chars. /* This doesn't
encourage me to comment! */
I find the visual symmetry between /* and */ very pleasing.
>
At least C++-like comments are two of the same char and don't need to
be ended!
But they are automatically ended by newline. If I
had a multiline comment it would drive me crazy
if I had to type at the beginning of each line //. It
gets on my nerves with shell or awk and you only
need to type # there.
>
// Aaah! I like commenting stuff this way!

I guess that this, again, has to do with the nature of C and the almost
total lack of care about whitespace.

At least it (C99?) accepts C++-style comments.
Yes , it's C99.
>
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?
Makes sense as opposed to what ?

As opposed to having a special data type called "bool". If nothing
else, it helps telling me what's a "boolean" and what's a "high number"
variable.
C99 has _Bool in stdbool.h. But internally they
may be still stored as an int.

Sep 11 '06 #5
Spiros Bousbouras wrote:
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?
>
Makes sense as opposed to what ?
As opposed to having a special data type called "bool". If nothing
else, it helps telling me what's a "boolean" and what's a "high number"
variable.

C99 has _Bool in stdbool.h. But internally they
may be still stored as an int.
"_Bool" isn't that pretty. Why did they decide on this, rather than
"bool"? Or am I missing something now?

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

Sep 11 '06 #6
KimmoA wrote:
Spiros Bousbouras wrote:
.... snip ...
>>
C99 has _Bool in stdbool.h. But internally they
may be still stored as an int.

"_Bool" isn't that pretty. Why did they decide on this, rather than
"bool"? Or am I missing something now?
To avoid invading the users name space. The user can #include
<stdbool.hto put define 'bool' as a synonym for _Bool, and to
define true and false.

This way C90 programs that did internal definitions for bool, true,
false can still compile under C99.

--
Some informative links:
news:news.annou nce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
--
Posted via a free Usenet account from http://www.teranews.com
Warning: Do not use Ultimate-Anonymity
They are worthless spammers that are running a scam.

Sep 11 '06 #7
"KimmoA" <ki****@gmail.c omwrites:
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.
"inline" is a valid keyword in C99, but not in C89/C90.

C89 is the 1989 ANSI standard, the first official standard for the
language. In 1990, ISO adopted the ANSI standard (with some cosmetic
changes that don't affect the language in any way, such as renumbering
the sections of the standard document); ANSI then adopted the ISO
standard. C89 and C90 are two different standard documents that
describe the same language.

C99 is the 1999 ISO standard. Officially, it supersedes and replaces
the C90 standard, but very few implementations fully support it.
Unfortunately, it is not yet possible to use C99 features in portable
code.

C90 is almost completely supported, but few compilers yet implement
all of C99. Many compilers implement *some* C99 features, but
different compilers don't necessarily implement the *same* C99
features. And a lot of the new C99 features require support in the
runtime library, which may come from a different provider than the
compiler.

"inline" in particular was a fairly common extension even before C99.
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".
:(
Just call it "hi_score". "hi-score" already has a meaning:
"hi - score". I suppose C could have required whitespace around
operators, but the language itself tends not to impose style rules,
and sometimes you might want to use operators without whitespace for
emphasis:

x + y*z
3) Is using "const" in C considered good practice? I have had little
need to do so so far thanks to #define.
It's good practice, but remember that "const" doesn't mean "constant";
it means read-only. Unlike in C++, an object declared "const" doesn't
give you something you can use in a constant expression; it just means
that you can't modify the object.

const int x = 42;
x = 43; /* illegal, x is const */
switch(some_exp r) {
case x: /* illegal, x is not a constant expression */
...
}
4) I kind of hate C-like comments. I use C++ comments mostly in my C
programs. Is this evil?
It means your program can't be compiled by a strict C90 compiler. It
also means that, if you post your code here, you're likely to have
syntax errors. News software often wraps long lines. If a "/*
.... */" is wrapped, it's still a comment; if a "// ..." comment is
wrapped, the end of it is no longer part of a comment, and will
introduce a syntax error *if you're lucky*. (If you're unlucky, it
will happen to compiler anyway.)
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?
C99 has _Bool as a keyword; the new <stdbool.hheade r defines "bool",
"false", and "true". (Why the ugly keyword? "bool" is a legal
identifier in C90, and a lot of C90 code defines its own bool type;
making "book" a keyword would have broken such code.)

The comp.lang.c FAQ is at <http://www.c-faq.com/>. Read section 9,
"Boolean Expressions and Variables".

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 11 '06 #8
CBFalconer wrote:
"_Bool" isn't that pretty. Why did they decide on this, rather than
"bool"? Or am I missing something now?

To avoid invading the users name space. The user can #include
<stdbool.hto put define 'bool' as a synonym for _Bool, and to
define true and false.

This way C90 programs that did internal definitions for bool, true,
false can still compile under C99.
.... at the expense of beautiful code and, IMO, rendering _Bool useless.
(Why the capital 'B' anyway?)

I didn't even know about C90. I thought that there were only two real
standard specifications of C ever: C89 and C99.

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

Sep 11 '06 #9
"KimmoA" <ki****@gmail.c omwrites:
CBFalconer wrote:
"_Bool" isn't that pretty. Why did they decide on this, rather than
"bool"? Or am I missing something now?

To avoid invading the users name space. The user can #include
<stdbool.hto put define 'bool' as a synonym for _Bool, and to
define true and false.

This way C90 programs that did internal definitions for bool, true,
false can still compile under C99.

... at the expense of beautiful code and, IMO, rendering _Bool useless.
(Why the capital 'B' anyway?)
What expense? If you want to use "bool", "false", and "true" in C99
code, just put a "#include <stdbool.h>" at the top of your source
file.

The capital 'B' is there so the keyword is in the namespace reserved
to the implementation. The identifier "_bool" can legally be used in
C90 user code in some restricted circumstances; the identifier "_Bool"
cannot.

But you don't need to use "_Bool" at all.
I didn't even know about C90. I thought that there were only two real
standard specifications of C ever: C89 and C99.
C90 is the same language as C89 (see my other response in this thread
for details).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 11 '06 #10

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

Similar topics

1
2596
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
9520
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
2198
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
8375
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
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
8815
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
8707
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
8593
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
5622
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
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
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
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.