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