• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Type of @true in Obj-C vs Obj-C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Type of @true in Obj-C vs Obj-C++


  • Subject: Re: Type of @true in Obj-C vs Obj-C++
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 10 Jul 2013 09:51:54 +0200


Le 9 juil. 2013 à 20:56, Jens Alfke <email@hidden> a écrit :


On Jul 9, 2013, at 11:31 AM, Scott Ribe <email@hidden> wrote:

I don't see what @true/@false have to do with true/false.

@true is a shortcut for @(true), so the compiler first evaluates ‘true’ and then boxes the result.

I think the issue is that the auto-boxing code has a special case for the Obj-C YES/NO constants that outputs boolean-type NSNumbers instead of 0/1, but it doesn’t have the same special case for the C99 ‘bool’ type.


On Jul 9, 2013, at 02:48 , Jean-Daniel Dupas <email@hidden> wrote:

No, unless you redefine the true and false macros.
The C standard specifies that true and false are macro that expand to integer constant with value 1 and 0 respectively.

In C99 ‘true’ and ‘false’ are builtin constants of type ‘bool’, not macros. (Right? IANALL.)

C99 defines a _Bool type, but it did not introduced new builtin constants for true and false.
true and false are expected to be defined by <stdbool.h>. If you don't include this header, trying to use true or false will result in an undefined identifier error.

And to quote the C11 standard:

7.18 Boolean type and values <stdbool.h> 

  1. 1  The header <stdbool.h> defines four macros.

  2. 2  The macro

    bool expands to _Bool.

  3. 3  The remaining three macros are suitable for use in #if preprocessing directives. They are

    true

    which expands to the integer constant 1,

    false

    which expands to the integer constant 0, and

    _ _bool_true_false_are_defined

    which expands to the integer constant 1.

  4. 4  Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then

    redefine the macros bool, true, and false.259) 

-- Jean-Daniel




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Type of @true in Obj-C vs Obj-C++ (From: Rick Mann <email@hidden>)
 >Re: Type of @true in Obj-C vs Obj-C++ (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Type of @true in Obj-C vs Obj-C++ (From: Rick Mann <email@hidden>)
 >Re: Type of @true in Obj-C vs Obj-C++ (From: Scott Ribe <email@hidden>)
 >Re: Type of @true in Obj-C vs Obj-C++ (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: TDD : Prior test failures in Issues Navigator are annoying
  • Next by Date: OS X Crash Log Symbolication
  • Previous by thread: Re: Type of @true in Obj-C vs Obj-C++
  • Next by thread: TDD : Prior test failures in Issues Navigator are annoying
  • Index(es):
    • Date
    • Thread