C || C++ || C using some C++ features?

Started by
5 comments, last by ThoughtCriminal 21 years, 2 months ago
I've seen threads here about should I use C. Sould I use C++. Should I use laguage 'X'? Anyway, I curious how many here use a hybrid of C and C++? Or do you try to use only C or only C++? I would personally use the hybrid version, but thats because I'd be moving up from assem. I've done some C and C++. The only thing I really like about classes is operator overloading(Is function overloading a C++ only thing? Cause I like that too.) What kind of problems could I run into(new vs. malloc)(STL) Thanks. [edited by - ThoughtCriminal on February 16, 2003 2:14:13 AM]
Advertisement
I always find these questions rather odd. The notion of a C/C++ "hybrid" is rather curious, when you pause to consider that C++ is essentially a superset of C. "Hybrid code" would then merely be C++ code that doesn''t make use of all of the features that the language offers.

Overloading, whether it is of functions or operators, is not possible in C. Other notable C++ features include templates and exceptions. (I would mention inline functions and the const keyword to replace #defines, but I''m not sure whether either or both of these features have made it into later revisions of C as well.)
since most of c is valid c++, the distinction between "c", "c++", and "a hybrid of c and c++" is really hard to spot when you''re using a c++ compiler.

most people use c++ as a "c with classes". using advanced c++ features often requires a good design that aims at using those features, planning ahead, extensive knowledge of the language and computer science in general, and experience. a small percentage of all c++ developers utilize much of the functionality of c++ that''s not present in c, especially so on a large scale (ex: writing a templated max function vs writing game engine core heavily based on templates).
I don't know what you mean about using a hybrid C / C++ system? If you write in C++, you are allowed to use any element of C that is still in the C++ langauge (don't go writing typedef struct ...). Anyone who tells you that you aren't supposed to use the FILE I/O system from C, or malloc / free, or sprintf ... well there just too stupid to be professional programmers ... and chances are they aren't.

I have been a professional C++ programmer for years, doing embedded audio processing systems, doing gambling games, and various other niche areas, - my first job was to rewrite an ASM based Keno game in ANSI C.

While I don't personally use C file I/O (because I know the stream library better), the lead programmer used it to implement our filing classes, not for performance reasons, but because he had more experience with it. There was abolutely no issue either, he used the older system for his area, I used the C++ system in mine, and since the 2 do not interact at an internal level, they play perfectly fine together. Also, my logging system uses the C++ stream operators, but for him I added support for a var args macro, and now everyone in the company uses the feature (so you might call it a hybrid system, but I say it's just real C++).

As for the area of classes, vs. structures, vs. global functions / variables ... that isn't even a C++ issue, C++ doesn't dictate that you should use classes, hell the only thing it dictates is that you MUST use at least one function which does NOT belong in a class ... main() ... just like C.

So anyone who says using the C part of C++ is not true C++ just doesn't get it, the language is there to solve programmer's problems, and the reason they left the C parts in, is because they really do make your life easier some of the time, just like the new elements (classes, templates) really do make a programmer's life easier as well.

[edited by - Xai on February 16, 2003 2:28:00 AM]
side note, if you take the time to learn stringstream, you can do some really great things with C++ formating ... but if you want the quick and dirty ... sprintf still rocks everyone''s world.
if (your code is compiled using a C++ parser)  the code is C++;else if (your code is compiled using a C parser)  the code is C;else  who_the_hell_cares = null; 


sprintf: so good, it makes you want to slap yo momma! *slap*

[edited by - Nypyren on February 16, 2003 4:35:56 AM]
Or you could use Objective-C for a radically different take on object-orientation... still using C.

[ 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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement