/g/ - Technology

install openbsd

[Make a Post]
[X]





C89 Best Language? Nanonymous No.1074 [D][S][L][A][C] >>1075 >>1103 >>1210

Is c89 really better than any other language ever? Or should I go with c99?

Nanonymous No.1075 [D]

>>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);
}

Nanonymous No.1077 [D]

>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.

Nanonymous No.1103 [D]

>>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.

Nanonymous No.1210 [D] >>1211

>>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.

Nanonymous No.1211 [D] >>1214

>>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).

Nanonymous No.1214 [D] >>1227

>>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.

Nanonymous No.1218 [D] >>1255

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.

Nanonymous No.1221 [D] >>1222 >>1223 >>1255

>if(bool1 == bool2)
if((bool1 && bool2) || (!bool1 && !bool2)) achieves the same result.
>inb4 HURR ITS TOO COMPLICATED

Nanonymous No.1222 [D] >>1224 >>1255

>>1221
>if((bool1 && bool2) || (!bool1 && !bool2)) achieves the same result.
You are doing 4 comparisons instead of 1

Nanonymous No.1223 [D] >>1224 >>1255

>>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.

Nanonymous No.1224 [D] >>1230

>>1222
It's going to expand to the same amount of work when it's compiled anyway.
>>1223
>Hurr just add extra useless bloated shit because it saves me 5 seconds of typing
pajeet

Nanonymous No.1227 [D] >>1230

>>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.

Nanonymous No.1230 [D]

>>1224
>saving typing
>pajeet
Do you think perl is peak pajeet language? Do you think pajeets care about typing when they copy-paste and autocomplete everything?
>>1227
But this could be done with a typedef and accomplish the same thing.

Nanonymous No.1231 [D] >>1234

>>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.

Nanonymous No.1234 [D] >>1236

>>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.

Nanonymous No.1236 [D] >>1255

>>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.


Nanonymous No.1255 [D] >>1273

>>1236
>>1218
>>1221
>>1222
>>1223
Lol plebs
if (!!bool1 == !!bool2)
is idiomatic and is a perfect replacement for the useless bool type. Bool type is for massive pajeets who can't do simple logic.

Nanonymous No.1273 [D]

>>1255
>if (!!bool1 == !!bool2)
>pajeet
Look at the "nice" assembly this produces, ebin droll.