5 ms·
A lot of their "improvements" could be done just by using C99 designated initializers.
by kayamon 10y ago
A lot of their "improvements" could be done just by using C99 designated initializers.
- mlvljr 10y agoAnd why the downvotes? Class-based wrappers may very well add confusion, overhead and leaky abstractions, not to mention bugs.
- astrange 10y agoAnd why are they claiming C doesn't have type-safe enums?
- banachtarski 10y agoBecause C doesn't have type-safe enums. edit: for the downvoters, I'd LOVE to be happily corrected with a link to documentation about C language support for a type safe enum.
- loeg 10y agoIt isn't type-safe in the sense you're used to in C++. But common pitfalls can be avoided if you don't destroy the type information by assigning through a vanilla integer. enum a { A }; enum b { B }; static enum a a = B; $ clang -Wenum-conversion -Werror a.c b.c:4:19: error: implicit conversion from enumeration type 'enum b' to different enumeration type 'enum a' [-Werror,-Wenum-conversion] static enum a a = B; ~ ^ 1 error generated.
- banachtarski 10y agoThe easy ability to assign it to a vanilla integer or cast it implicitly (through an arithmetic operator or comparison for example) is what I mean when I say they aren't typesafe. A warning is also a fair bit weaker than a flat out compile error, although I'll grant that compiling with -Werror (a really challenging thing for most companies) alleviates that.
- loeg 10y agoYeah, it isn't real type safety. That said, don't assign enums through vanilla integers if you don't have to. :-) Our engineering organization of 300+ people builds the majority of our code with -Werror (and a bunch of warnings enabled). Just an anecdote, of course.
- loeg 10y agoI don't know why this is downvoted. Several of the author's claims about C are just wrong. Modern C compilers can warn you about most of these, and literal initializers eliminate the missed zero initializations.