Archived

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

Unidentified

C in C++: Good or Bad?

Recommended Posts

Unidentified    136
I'm looking through a book(Strategy Game Programming with DirectX 9) and it uses C++ for it. It also uses C, I haven't started reading it and I'm not for a month or so but it uses functions that I have to port to C++ in some SDL tutorials. Are C functions like Memset, sprintf, fgets, etc... good to use in C++ programs and is it good to use the FILE* data type? I'm just wondering, I know how to use it and I feel more comfortable using that since I have more experience in C but I like to stay strictly to C++(only because I heard it was bad to use C habits in C++) when I'm programming in C++. I would find it easier to use C functions but is it a bad habit to do so? Does a book that does so have bad style? EDIT: This is a bit off topic but, I'm currently using SDL and the tutorial I'm using uses bitmap fonts, I heard that the SDL_tff library is good and it uses TrueType fonts. Which one should I use? [edited by - Unidentified on January 24, 2004 11:13:21 PM] [edited by - Unidentified on January 24, 2004 11:14:02 PM]

Share this post


Link to post
Share on other sites
Unidentified    136
OK, thanks. So does that mean that it just depends on what you like? I didn''t do it before because about every post mentioning C and C++ states "C and C++ are different languages." and "C teaches bad habits.", etc...

Share this post


Link to post
Share on other sites
evolutional    1393
While they are true, I always argue that when using things such as the windows API, you''re using C-style code. Even newer projects like LUA are written in C, causing people to mangle C and C++ code together, whilst not ideal - the situation isn''t nearly as clear cut as the elitists wish.

If you''re learning, I''d say do whatever you wish to; do it in a way that you learn the strengths and weaknesses of each way. Learn why you do something, not because it''s what someone else told you. For example; I used to malloc() everything - now I ''new'' it in C++. Simply because I feel more comfortable doing it after I learned what the new / delete operators did.


Share this post


Link to post
Share on other sites
Zahlman    1682
The nice thing about C++ is how much freedom you have to do things at a relatively high, or low level.

The problem with C++ is that you seem to have to be adept at both in order to do anything that will make people consider you competent. Or in some cases, just to get the damn stuff to compile. (You have to get too many low-level details right IMHO when you try to work at a high level.)

Share this post


Link to post
Share on other sites
Mayrel    348
Strictly, there''s no such thing as "C in C++". C++ includes many of the features of C, but any code you write in C++ is C++, even if it would also compile in C.

Using memset, sprintf, strlen and other functions from the C library is fine, because the C library is part of C++. It''s there for a reason: so that you can use it.

Some external libraries, like SDL, are written in C, but that doesn''t stop you using them in C++. The language a library was written in is largely irrelevant: you can use a library written in Pascal, or even, gods forbid, COBOL, with C++.

Yes, C++ isn''t the same language as C. Yes, it has new features, some of which are much better than the alternatives in C. However, it''s specifically designed to be compatible with C and C libraries.

Unless you do something stupid, like trying read a file using stdio and iostream at the same time, C and C++ live together quite happily.

CoV

Share this post


Link to post
Share on other sites