Eirik said:
I believe that I am starting to understand the C language
satisfactory, but a there are a few things that I still not
understand(Feel free to direct me to a tutorial or a FAQ
if these questions are explained in a good way or are in a
FAQ somewhere):
See my signature for a list of FAQs.
1) What is the difference between a struct and a union?
In a struct each field (member) has its own storage area.
In a union, each field shares the same storage area. The
area allocated is the size of the largest field.
2) What does the static keyword mean?
What does it do?
The 'static' keyword has different meanings depending
on _where_ it is used. If it is used at file scope,
i.e. not in a function, it restricts the visibility
of the variable to only within the file. When it is
used in a function or statement block, it marks the
variable as "permanent", such that the variable has
the same life-time as a global or automatic variable.
3) Why is it better to say 'const char *' than 'char *'
(if it is)?
This is in the FAQ. Search for "const correctness".
There are 4 combinations:
char * -- pointer to a character variable.
const char * -- pointer to constant data.
char * const -- pointer is constant.
const char * const -- constant pointer to const data.
The "better" usage depends on the situation. Pointers
to literal should be pointers to constant data. Pointers
to strings (i.e. modifiable text), should be "char *".
If the you don't want the pointer to change, then use
a constant pointer "char * const".
Elaborate please.
In general, enums can be used anywhere that an integer
is used. Depending on the enum's value, it may also
be used where a char, or short is required.
Enums are a method for the compiler to generate values
for named constants. The C syntax also allows the
programmer to specify the values.
Read the C FAQ. Also search the newsgroup for "welcome".
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book