Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

well, compile with a C++ compiler and just use RAII ?


It's not that easy.

A modern C++ compiler will have all sorts of issues with fundamental C idioms, and depending on C++ is a very different story from depending on C.


C++ compilers do not have issues with fundamental C idioms.

I maintain a significant body of code which compiles as C or C++. The executable size and performance are about the same.

A C++ compiler will, of course, have "issues" with C99 and C11 features, that's for sure.


Running without exceptions is one C idiom. RAII, operator-new, and many other C++ features break down without them.


Obviously, I do not use RAII, operator new or exceptions in a code base that compiles as C or C++.

Here let me note that I have not gone out of the way to disable anything in C++. I have not disabled EH in the compiler, or RTTI or anything. Yet, the executable size is close to the C one, and the performance is basically the same.


> Running without exceptions is one C idiom

well, did you know that for instance the windows C library was implemented in C++ ? and yet we don't see it throwing exceptions left and right.


Which idioms are you referring to?


Automatic void casts, flexible struct fields and calculating offsets to find the containing struct given a field are three that I use all the time. Last time I checked, C++ wasn't very impressed by either one.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: