• 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: Block variable syntax related question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Block variable syntax related question


  • Subject: Re: Block variable syntax related question
  • From: Andreas Grosam <email@hidden>
  • Date: Sun, 11 Sep 2011 08:38:56 +0200

On Sep 10, 2011, at 12:49 AM, Scott Ribe wrote:

> On Sep 9, 2011, at 3:47 PM, Jens Alfke wrote:
>
>> Like, make BOOL a typedef for bool?
>
> On OS X, bool is 32 bits. So they're not strictly compatible.

This may be implementation defined. According C99:

6.2.5 Types
An object declared as type _Bool is large enough to store the values 0 and 1.

They are not compatible because their "integer conversion rank" is different, and because of this:

6.3.1 Arithmetic operands
6.3.1.2 Boolean type
When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.


The following program demonstrates the difference:

#import <Foundation/Foundation.h>

static int from_BOOL(BOOL b) {
    return b;
}

static int from_bool(bool b) {
    return b;
}

int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"from_BOOL(%d) = %d", 4, from_BOOL(4));
    NSLog(@"from_bool(%d) = %d", 4, from_bool(4));

    [pool drain];
    return 0;
}

Output:

2011-09-11 08:26:50.561 BOOL[3700:707] from_BOOL(4) = 4
2011-09-11 08:26:50.562 BOOL[3700:707] from_bool(4) = 1





 _______________________________________________
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: 
 >Block variable syntax related question (From: David Hoerl <email@hidden>)
 >Re: Block variable syntax related question (From: Bavarious <email@hidden>)
 >Re: Block variable syntax related question (From: Jens Alfke <email@hidden>)
 >Re: Block variable syntax related question (From: Scott Ribe <email@hidden>)

  • Prev by Date: Where is Customize button in Xcode 4.1 installer?
  • Next by Date: Re: Where is Customize button in Xcode 4.1 installer?
  • Previous by thread: Re: Block variable syntax related question
  • Next by thread: Re: Block variable syntax related question
  • Index(es):
    • Date
    • Thread