Why is the Objective-C Boolean data type defined as a signed char?

Something that aroused my interest was the definition of the BOOL Objective-C type.

Why is it defined as a signed char (which can cause unexpected behavior if it is assigned a value greater than 1 byte in length) and not as int , since C (much less margin for error: a zero value is false, a value other than zero is equal to true)?

The only reason I can think of is to create an optimization store for Objective-C designers, since char will use less memory than int . Please can someone enlighten me?

+4
source share
1 answer

Remember that Objective-C was created back in the 1980s when it is important to save bytes.

As mentioned in the comment, as long as you stick to the YES and NO values, everything will be fine.

+6
source

Source: https://habr.com/ru/post/1306065/


All Articles