My point is basically that in domain-specific cases, C can be a good choice because of the lack of sugar and simplicity. I doubt this applies to most cases though.
Why artificially limit your code to C?
21–30 of 40 posts
Re: Why artificially limit your code to C?
#22No one there mentions symbol scrambling, and how it makes C++ libraries unportable across multiple compilers for the same platform.
Re: Why artificially limit your code to C?
#23"I wanna use maaaaaap! Why can't I use map? Map map mapmaapmap."
"Because this stuff runs in an interrupt handler, and is shared with thread-world code through a very carefully designed API involving a couple layers of synchronization. Many Bothans died to make this work well, and fast."
"No map?"
"No map. Go read about NUMA."
"What about streams?"
[buries head in hands]
tl;dr; It's an idiot shield. Kids, get off the lawn :-)
Re: Why artificially limit your code to C?
#24The fact that C++ is almost a superset of C is commonly used as an argument for C++, and the accepted answer in the post is a common response - C++ is not quite a superset of C, you have to cast malloc, you lose out on C99 features, etc. But I think it misses the point: if you could really get the advantages of C++ by using its features in a few necessary places in your C code, I think it would be worth it to make yo…
> where the caller of your method is a closing brace Although I agree with the sentiment of your comment destructors and RAII in general are arguably the best C++ features. If I were forced to use C++ again I would restrict my code to a lightweight subset of C++, especially I would not use the C++ Standard library (STL, iostreams, string) and of course not use BOOST (or any template heavy library) and C++0x. But I wo…
Re: Why artificially limit your code to C?
#25But there are many practical reasons as well. One that hasn't been discussed much is exceptions. In order to use C++ libraries in C code you'd have to "RAIIfy" your entire codebase. That means wrapping all dynamic memory allocations in their own objects and replacing malloc with new. What's left of C after doing that?
Switching off exceptions on the compiler level isn't a viable solution either because it leads to undefined behavior.
Re: Why artificially limit your code to C?
#26No one there mentions symbol scrambling, and how it makes C++ libraries unportable across multiple compilers for the same platform.
Actually this is mentioned by "Rhythmic Fistman", but the post only got 6 points. From a purely practical standpoint, the lack of an ABI is the #1 reason I don't bother with C++ anymore because chances are pretty good that I'll want to interface the lower-level code with something like Python or Go, both of which integrate with C code much more easily than C++.
Re: Why artificially limit your code to C?
#27Earlier quoted context omitted.
> where the caller of your method is a closing brace Although I agree with the sentiment of your comment destructors and RAII in general are arguably the best C++ features. If I were forced to use C++ again I would restrict my code to a lightweight subset of C++, especially I would not use the C++ Standard library (STL, iostreams, string) and of course not use BOOST (or any template heavy library) and C++0x. But I wo…
What would you use for string handling, then? Please don't tell me you prefer strcpy/strcat and zero-terminated strings?
Re: Why artificially limit your code to C?
#28No one there mentions symbol scrambling, and how it makes C++ libraries unportable across multiple compilers for the same platform.
Everyone loves to bash the lack of a C++ ABI. Now please name another language with native implementations with a standard ABI across different compilers. C implementations have a standard ABI, because they usually are the operating system ABI.
Re: Why artificially limit your code to C?
#29Earlier quoted context omitted.
> where the caller of your method is a closing brace Although I agree with the sentiment of your comment destructors and RAII in general are arguably the best C++ features. If I were forced to use C++ again I would restrict my code to a lightweight subset of C++, especially I would not use the C++ Standard library (STL, iostreams, string) and of course not use BOOST (or any template heavy library) and C++0x. But I wo…
What would you use for string handling, then? Please don't tell me you prefer strcpy/strcat and zero-terminated strings?
Personally, I'd like to see a simple C string library using modified UTF-8 (to be compatible with ASCIIZ) which is grapheme aware.
I'm tempted to take a shot at writing one myself, but haven't gotten around to it yet. If anyone is interested, see http://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries for the algorithm and http://www.unicode.org/Public/UNIDATA/auxiliary/GraphemeBrea... for the property data...
Re: Why artificially limit your code to C?
#30Earlier quoted context omitted.
Everyone loves to bash the lack of a C++ ABI. Now please name another language with native implementations with a standard ABI across different compilers. C implementations have a standard ABI, because they usually are the operating system ABI.
I'm not sure what you mean here by "name another language". Do you mean other than C? I don't understand what that would demonstrate.