/g/ - Technology
install openbsd
[Make a Post]>>1074
I would prefer C99 because you can declare loop variables inside the loop rather than at the beginning of the block.
for (unsigned i = 0; i < 1000; ++i) {
printf("%d\n", i);
}
>Is c89 really better than any other language ever?
Where did you read this? c99 is all improvements. I really like the struct initialization stuff they added.
>>1074
The only advantage of C89 is its portability. If all the platforms you target have a C99 compiler, then use C99. Even compilers like TCC support C99 so the only reason to not use it is if you are programming for DOS or some similar platform.
>>1074
C99 has some cancerous features like C++ comments and useless new types such as bool. Don't bother using it unless you really need some feature from it.
>>1210
>C++ comments
I agree, one form should have been chosen.
>bool
How is it cancerous? A lot of people were already defining it with an enum.
>Don't bother using it unless you really need some feature from it.
Never use C89 since it doesn't have sane integer types (stdint).
>>1211
>A lot of people were already defining it with an enum.
The bool type is totally unnecessary. Why can't the fucking pajeets just use 1 and 0 instead of fucking around with a whole different type just to represent 1 and 0.
You know that a bool has to be 0 or 1, whereas an int or an enum could be anything. So if you have a bool, then you can do
if(bool1 == bool2)
or
x ^= bool1<<3;
and know that it will work as you expect.
>if(bool1 == bool2)
if((bool1 && bool2) || (!bool1 && !bool2)) achieves the same result.
>inb4 HURR ITS TOO COMPLICATED
>>1221
>if((bool1 && bool2) || (!bool1 && !bool2)) achieves the same result.
You are doing 4 comparisons instead of 1
>>1221
Yeah no shit. In the general case you can write
bool = bool?1:0;
It really doesn't hurt to have a type that says the same thing though.
>>1214
It's godsend to make function prototypes clearer.
Something like `bool file_check(bool follow_symlinks, const char *path)` is way better than using ints or chars.
>>1226
The whole point of c is taking high level concepts like functions and objects and implementing them in as low level a way as possible, so that they still run fast and can still be debugged. Adding a bool type adds zero complexity to the language, because they literally compile to that little ternary operation I showed. But in turn they represent the high level concept of a boolean, and let you treat them the same as you would a boolean in a scripting language like python.
>>1231
>adds zero complexity to the language
I can swear that adding the boolean type causes an extra 100-200 lines to be added to the compiler, with maybe another 50 lines of headers. That is a nontrivial amount compared to the very idiomatic and easy to understand ternary/conditional expressions used earlier in this thread.
>>1234 (nice digs)
I just glanced through the standard. _Bool is referenced 12 times in the language section. All of the references can be derived from the ternary example, or are a listing of types/keywords that _Bool is included in. So a compiler writer could, at their option, literally compile a bool cast to ?1:0 and do nothing more. If they want to turn that into 1000 lines of obfuscated assembly, then that's on them, but the actual complexity of the language introduced is barely anything.
[Catalog][Overboard][Update]
[Reply]18 replies
Is c89 really better than any other language ever? Or should I go with c99?