On 10 June, 14:33, "(e-mail address removed)"
(I
understand by the name C++ is an extension of C
that's what the name implies but there are enough additions and
changes
to C++ to make it, really, a different language. Although most well
written
C will compile and execute correctly with a C++ compiler in reality
idiomatic C++ doesn't look much like idiomatic C.
and there are objects
in C++ and I don't see why each google C query leads to a C++ forum or
site or why C is most of the time link to C++ ?
bad luck. Some people confuse the two (maybe google does).
I feel attracted in C because of the freedom in coding it gives,
unlike coding with objects
I don't think OO programming is significantly "less free". Whatever
*that* means!
where I think objects are less easy to deal
with when facing someting new and unexpected.
they're actually pretty good with the new and unexpected things
but they add to the beginner's learning curve. Particularly
a language like C++ which is C with objects (and other stuff!)
added. Remember most C programs are also C++ programs
(or close to).
Of course, on the other
hand, objects are more powerful. I am not sure why.
their advantages may not be very obvious until you
start to deal with large programs. They allow you to break
a large program into small pieces (C provides techniques
to do this as well). This modularisation is what allows
complex systesm to be developed. Some of the most
complex artifacts on earth are computer programs.
It might be
because I have no idea of what objects bring as advantages over lines
of codes.
even objects end up as lines of code somewhere!
Someone says at this point, it's not a priority to learn how to debug.
it's a priority to learn how to write correct programs!
If you can't write 'em correctly from scratch (and few people can)
you're going to have to debug 'em some how!
Note "debug" does not necessarily mean "use a debugger".
[hi richard!]
Often
it means examine the output or output from intermediate stages
and reason about the program until you work out why the behaviour
of the program is different from that which you expect. A debugger
can help you do this but it isn't the only way.
- good quality logging
- test suites
- run time assertions
- prrofs of correctness (these are hard actually!)
So I'll come back later when I'll have bigger program in size, I
understand it should make more sense then.
if you can't write small correct programs you won't write big correct
programs.
By the way, I'm not putting anything such as functions away, it's just
I am following book chapters.
In the 2 books I am learning from, functions come just after
pointers ... but in one book (the most difficult but more complete one
"from G. Willms - french Version published by PC Poche") pointers come
far after arrays but still before functions.
In the other book written by "Tony Zhang published in french by Campus
Press / Pearson education") Pointers precede Arrays and Functions.
So, in both books, functions come after arrays and pointers...
But before getting on functions which I believe is something huge,
you may be pleasantly surprised. I'd say functions were absolutely
fundamental to programming. But that doesn't really make them hard.
For technical reasons C needs pointers to do certain things with
functions (pass modifiable arguments) that other languages do by
other means. C is very low level" Very close to the machine. This
is its blessing and its curse.
I'd first look at preprocessor things.
the preprocessor is pretty ugly, but necessary
Some people in this topic say the books I am studying from might be
old. Doest it make a difference at a starting level ? Is there a new C
standardized version that revolutions things ?
C divides up in to roughly three eras.
1. pre-1989 there was no formal standard but a defacto one
2. 1989 standard
3. 1999 standard
The 1989 standard will still run all the well written pre-standard
stuff. You don't seem to be writing to the pre-1989 "standard"
so ignore it. The 1999 standard was very slow to be adopted. It is
*still*
not widely implemented and many users who value C for its portability
use the 1989 standard. Your code looks ok for either 1989 of 1999.
They didn't discard anything important in the 1999 standard (pre-1989
code might have problems).
At this point I'm not focusing on portability. Should portability be a
subject to focus on at this beginner level?
not really, but if you know a portable way to do something
why not do it? Running on Windows and Unix will tend to draw
your attention to really non-portable things.
===O===
There are many stuff in the script initially posted where my
understanding is low.
Ex. : atoi(buffer) ;
Does it says to convert alphanumeric characters to integers?
It's the first time I see atoi.
yes. You need a good reference. Eg. K&R. But this isn't bad:-
http://www.dinkumware.com/manuals/default.aspx#Standard C Library
just typeing "atoi" into google has a good chance of answering your
question.
In the book where the script is taken from, it says about atoi it
checks if the number only has zeros in it.
this sounds wrong. Do you mean "...only has digits in it"?
So, I understand atoi() returns a boolean value.
nope. Booleans are either true or false. atoi() returns an integer.
I'll try to use strtol instead, I have never seen it but i'll try to
remember about atoi and strtol or strtoul and the same for gets and
fgets.
atoi() isn't as bad as gets(). atoi() only gives you the wrong
answer, gets() opens a gigantic security hole that allows all sorts
of exploits and virii.
===O===
The most difficult thing to understand there was
while ( *pc++ == *pb++ )
;
that is rather idiomatic
From my understanding, it says as a loop until an empty value is
return to copy the content/variable of * pb into * pc and right after
to increment pb and pc then, the loop restarts and says to copie pb
into pc ...
Is it the right understanding ?
Is it as correct as :
while (* pb) /* while * pb != 0 */
{
* pc = *pb ;
pb ++ ; pc++ ;
}
yes. excellent!
===O===
I first came here to learn how to debug but it seems there are people
who have answer to my C related question, google takes me most of the
time to C++ forum and websites.
Thanks,
no problem