my freind on msn said sometimes its acceptable(he says he's much smarter than me at this) to sometimes use c code with c++
is this true and if so when but i dont think it is
Printable View
my freind on msn said sometimes its acceptable(he says he's much smarter than me at this) to sometimes use c code with c++
is this true and if so when but i dont think it is
When you don't want to reinvent the wheel.Quote:
Originally Posted by lilhawk2892
Well, in almost all cases, C++ has an improved alternative to the original C method of getting something done. When programming in C++, I rarely find any need to use the C method to do anything. Keep in mind, much of the libraries used in C are still used in C++, for instance <cmath> and <cctype>. Now, if you're porting C code to a C++ program, it's generally fine to leave the C as C and just build the C++ around it so long as the C still works. As they say, if it isn't broken, don't fix it.Quote:
Originally Posted by lilhawk2892
thanks im gonna show this to him see what he says
For many cases, yes, I'll agree. But there are libraries out there that are written in C: libcurl, SDL, pthreads, Win32 API, etc. Some of these have C++ wrappers/equivalents. And some of us use the C version anyways. I've intermixed C++ with all of the above libraries except pthreads (it's only a matter of time).Quote:
Originally Posted by SlyMaelstrom
Mixing C libraries with C++ code is, imho, perfectly acceptable and good thing. Mixing C and C++ code together in the same project, eh, it's ok. But if you're the one writing it, you might as well take advantage of the features C++ gives you.
And the STL/C++ adds a lot of stuff to the binary. Especially when debugging - those suckers get big quick. (But with today's hard drives, this is moot. And it's debugging...) Though wxWindows is large no matter what...
Edit: Missed your comment about libraries... oh well. My 2cent.
Yeah, sometimes one uses C-style code when dealing with libraries or APIs that are written for C and C++ both. I'd never use C-style code within a C++ program in any other case, though. In general the C++ style is shorter and easier to understand.