Archived

This topic is now archived and is closed to further replies.

GravtyKlz

advanced C or go on to C++

Recommended Posts

GravtyKlz    122
Ide say I have an intermediate understanding of C. I was just wondering if I should go on to an advanced level of C and then getinto C++, or do both, or just stop doing C now. I''ve seen some C++ code and ive read some primers on it so I know enough to know what people are doing in their code(for the most part). Im more fond of C but I''ve always programed in C and nothing else. Thanks.

Share this post


Link to post
Share on other sites
Cat_B    122
Hey, great question, I''m wondering that too. I''m pretty good with complicated pointer notation but they aren''t second nature to me yet. I hope you get some good replies

Share this post


Link to post
Share on other sites
kuphryn    210
Going from C to C++ will introduce you to classes. Since you know structure, classes should be easy. Practice classes and inheritance.

Kuphryn

Share this post


Link to post
Share on other sites
Oluseyi    2103
Go to C++. Not because C isn''t a good (some would say great) language in itself, but because C isn''t a prerequisite to C++. If you want to learn C++, learn C++.

Having an understanding of C structs won''t really help you with classes (and remember that structs in C++ are classes), because C++ classes are about so much more than data aggregation. The principles of data hiding, abstraction, object-orientation, inheritance and ploymorphism have no C analogues, though you do say you are somewhat familiar with C++ so that should help.

Share this post


Link to post
Share on other sites
grbrg    126
I agree with Oluseyi. OO ist far more than just a new name - you will really implement a new concept of structuring your programs... And believe me: once you understand C++ and OO and you start to liek it, C will look very crude to you...

So, head on to C++!

------------------------------
"Reality is nothing, perception is everything!" - First Wizard Zeddicus Zu''l Zorander

Share this post


Link to post
Share on other sites
GravtyKlz    122
In that case tell me the best book on C++. Ide like to have something of good size that will cover things from the beginning and take it to an advanced level.

Share this post


Link to post
Share on other sites
Fruny    1658
"Essential C++" by S. Lippman
"Accelerated C++" by A. Koenig and B. Moo
"The C++ Programming Language" by B. Stroustrup
"The C++ Standard Library" by N. Josuttis

See also the book link in my signature.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
Diodor    517
quote:

Original post by Oluseyi

The principles of data hiding, abstraction, object-orientation, inheritance and ploymorphism have no C analogues, though you do say you are somewhat familiar with C++ so that should help.



IMHO,

Data hiding works in C at module level. My habit is to make a module responsible for the creation and storage of the main data objects in that module, and pass to the outside world only a handle (an integer identifying the object), limiting the visibility to zero. I believe using handles is a case of abstraction, since I can call a single function for different object types. Inheritance can be simulated in C by replacing the "is" relation between class and subclass with "has". Polymorphism is directly supported through function pointers (in C you''d have to maintain a vtable by hand).

Share this post


Link to post
Share on other sites
Oluseyi    2103
quote:

Original post by Oluseyi:
The principles of data hiding, abstraction, object-orientation, inheritance and ploymorphism have no C analogues, though you do say you are somewhat familiar with C++ so that should help.


Response by Diodor:
IMHO,

Data hiding works in C at module level. My habit is to make a module responsible for the creation and storage of the main data objects in that module, and pass to the outside world only a handle (an integer identifying the object), limiting the visibility to zero. I believe using handles is a case of abstraction, since I can call a single function for different object types. Inheritance can be simulated in C by replacing the "is" relation between class and subclass with "has". Polymorphism is directly supported through function pointers (in C you'd have to maintain a vtable by hand).

You can implement object-oriented design in virtually any imperative language (really, you can implement just about any paradigm in any other language, possibly with the exception of generics), often by resorting to coercing existing language features and being careful. The point remains, however, that C does not have intrinsic support for many OO features (methods must be implemented as member pointers-to-function; there is no possible mechanism to effect public, private or protected visibility; polymorphism in terms of base class pointers dispatching derived class methods requires a significant amount of work, void pointers, typecasting and a home-brew RTTI mechanism...). Of course it can be done - as mentioned before, cfront did basically this - but noone can argue against the statement that OO concepts and features are not a part of the C language paradigm.

[Edit: Confusing phrasing.]

[edited by - Oluseyi on March 7, 2003 6:15:59 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
"The C++ Programming Language"... The reviews say now for beginners. As I said I know C and I know some C++. I understand classes for the most part and that you can use functions in them. If I read a primer on C++ would that be enough for this book? Or do you think I could do it as is?

Share this post


Link to post
Share on other sites
Diodor    517
quote:

Original post by Oluseyi

You can implement object-oriented design in virtually any imperative language.



That is true but C and C++ are much closer together than a random procedural language is to a random OO one.

quote:

The point remains, however, that C does not have intrinsic support for many OO features (methods must be implemented as member pointers-to-function; there is no possible mechanism to effect public, private or protected visibility; polymorphism in terms of base class pointers dispatching derived class methods requires a significant amount of work, void pointers, typecasting and a home-brew RTTI mechanism...). Of course it can be done - as mentioned before, cfront did basically this - but noone can argue against the statement that OO concepts and features are not a part of the C language paradigm.



Agreed. I guess my point (which sort of answers the original question) is that since it is _possible_ and often practical to borrow OOP ideas from C++ to C, learning C++ is a good thing even for a C programmer. (Likewise, learning how to write OOP in C may give the C++ programmer a better insight of what happens under the hood. I remember I used virtual functions for a while until I finally got around to understanding function pointers and what a vtable really is.)

Share this post


Link to post
Share on other sites