3 ms·
> But to sum up the advantage of C: C is for when you don't want any surprises. It's a very un-surprising language. Actually, judging by the quantity of unspec
by ahomescu1 12y ago
> But to sum up the advantage of C: C is for when you don't want any surprises. It's a very un-surprising language.
Actually, judging by the quantity of unspecified/undefined/implementation-defined behaviors in the C spec, I'd say C is full of surprises.
- mtdewcmu 12y agoI've seen lists of those, and they are pretty esoteric. I don't think I've ever stepped on one accidentally.
- ahomescu1 12y agoHow about the problem that the sizes of the basic types aren't exactly specified. All that C requires is that: char < short < int < long < long long and that sizeof(char) >= 8, sizeof(short) >= 16, sizeof(int) >= 16, sizeof(long) >= 32, sizeof(long long) >= 64 (from Wikipedia). The fact that int is allowed to be 16 bits, 32 bits, 64 bits or almost anything else is IMHO very nasty and has produced quite a few problems.
- mtdewcmu 12y agoThat is a problem, but doesn't C++ have the same problem? The situation was better before 64-bit became popular, when int == long == 32 bits on any system that mattered (when 16-bit gave way to 32-bits, you couldn't be sorry about that, it was a relief). Somehow the transition to 64 bits got screwed up, and you can hardly trust the basic integer types anymore. I have started using the new stdint.h types wherever size is likely to be an issue.
- ahomescu1 12y ago> That is a problem, but doesn't C++ have the same problem? It does, but that wasn't the point. I wasn't defending C++.
- mtdewcmu 12y agoI guess I don't know what your point was.
- ahomescu1 12y agoThat C isn't predictable or well-specified, which is a real problem when writing portable or secure code ("oh shit" moments in C code don't just give programmers headaches, but have caused tons of vulnerabilities).
- mtdewcmu 12y agoNot predictable or well-specified in comparison to what? Buffer overflows are not caused by the language. They are a well-known risk of developing in native code. Well-known risks are not surprises. Part of being unsurprising is being one of the oldest and most popular programming languages. There's no excuse for being surprised by what's well known.
- ahomescu1 12y agoIn comparison to Java, for example. Java specifies integer and float semantics exactly, including what happens for things like over/underflow and division by zero. C leaves too much to be decided by the compiler writer or ABI. Buffer overflows aren't the only problem C has. For an interesting discussion and examples of bad behavior that C allows, please take a look at [1] (especially part 2 of that series) and [2] (yes, some of these are compiler shenanigans; the problem is that the C standard allows the compiler to go crazy). 1 - http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-... 2 - http://blog.regehr.org/archives/213 http://blog.regehr.org/archives/213