quote:
but why bother learning printf when you can use cout.
Because printf() is actually better at separating different layers of data (format string and inserted data) and is thus cleaner and easier to read. But I''ve already had my printf vs. cout flamewar this month, so I''m not going to continue on this topic.
A C++ programmer who doesn''t understand C must be a real idiot and shouldn''t be a programmer in the first place. The syntax of C++ only adds onto C. There may be some minor differences, but those do not make C code incomprehensible for a C++ programmer. Now if somebody doesn''t know how to use printf() - well, that''s possible, but I wouldn''t count that as not being able to read the language. It''s just one stupid function call, and even though it''s part of the language (as per the standard), the language can very well live without it (e.g. GUI programs don''t - or shouldn''t - use printf() or cout).
Of course, C++ code tends to be slower than classic C code. For example, virtual function calls do take longer than direct function calls because of the function pointer indirection. However, you''ll get the same speed penalty if you write OOP code in C - which is very possible, though it tends to get very messy.
Also, modern compilers typically support C and C++ equally well, so the support argument doesn''t really count anymore.
Even exceptions don''t make programs slower; they can even make them faster (less conditional jumps in the default execution path). However, they do increase the binary size because of the exception handler tables.
But all the OOP, ADT etc... goodness aside: sometimes, you just need to step back and view the big picture. I''ve recently joined an open-source game project which is heavily OOP. The map is represented as a class, and every field or node of the map is a class of its own, and is treated like one. Now this is just stupid because if you''ve just got a Field * to use you''re lacking essential additional information (such as the coordinates of the field inside the map).
It all boils down to sensible software design. C++ and OOP are no magic tools to make software design better. They can only help you implement the more advanced designs.
And now back to the original question: C tends to be used more with OpenGL because OpenGL was built for C, as stated before. I would like to mention that this was very clever indeed. Even in the days of OOP and C++, I would recommend that an API like OpenGL be built in a procedural way. Sometimes, power and efficiency comes from simplicity.
cu,
Prefect
Return to the Shadows