Live data from Hacker News

Truthiness in C

dxuuu.xyz

11–20 of 26 posts

Re: Truthiness in C

#11

Yeah, C now has bool natively... I'm quite confident the compiler will optimize that test-and-move away as soon as you use the bool for something, giving you the same assembly as a last century's `typedef bool int`.

Did you mean `typedef int bool`?

Re: Truthiness in C

#12
If I'm not mistaken, the `(bool)` is unnecessary due to how implicit conversion works: `In a return statement, the value of the operand of return is converted to an object having the return type of the function` [1] ...unless I understood it incorrectly :/

[1] https://en.cppreference.com/w/c/language/conversion

Re: Truthiness in C

#13

If I'm not mistaken, the `(bool)` is unnecessary due to how implicit conversion works: `In a return statement, the value of the operand of return is converted to an object having the return type of the function` [1] ...unless I understood it incorrectly :/ [1] https://en.cppreference.com/w/c/language/conversion

That's correct.

Re: Truthiness in C

#15

Yeah, C now has bool natively... I'm quite confident the compiler will optimize that test-and-move away as soon as you use the bool for something, giving you the same assembly as a last century's `typedef bool int`.

Did you mean `typedef int bool`?

[deleted]

Re: Truthiness in C

#18

Yeah, C now has bool natively... I'm quite confident the compiler will optimize that test-and-move away as soon as you use the bool for something, giving you the same assembly as a last century's `typedef bool int`.

C has had _Bool natively since the 1999 ISO standard (24 years ago). The standard header has "#define bool _Bool". (The ugly name "_Bool" was chosen to avoid conflicting with existing code.)

The upcoming C23 standard will define "bool" as a keyword.

Re: Truthiness in C

#19

Yeah, C now has bool natively... I'm quite confident the compiler will optimize that test-and-move away as soon as you use the bool for something, giving you the same assembly as a last century's `typedef bool int`.

Did you mean `typedef int bool`?

No, _Bool is a distinct type, introduced by the 1999 edition of the standard.

Re: Truthiness in C

#20
post #18

Yeah, C now has bool natively... I'm quite confident the compiler will optimize that test-and-move away as soon as you use the bool for something, giving you the same assembly as a last century's `typedef bool int`.

C has had _Bool natively since the 1999 ISO standard (24 years ago). The standard header has "#define bool _Bool". (The ugly name "_Bool" was chosen to avoid conflicting with existing code.) The upcoming C23 standard will define "bool" as a keyword.

More significantly, true and false are now keywords.
Post reply on HN