Amazon.com Widgets 3rd printing p265 location 5921 error
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 11:26:53 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Errata
| | |-+  3rd printing p265 location 5921 error
Pages: [1]   Go Down
Print
Author Topic: 3rd printing p265 location 5921 error  (Read 512 times)
xjames
Newbie
*
Posts: 26






« on: September 18, 2011, 05:26:53 PM »

unless I did something wrong, when I ran prog 13.9 modified with the __block modifier, my output is
foo = 15
foo = 20

which would make sense (the book currently says
foo = 10
foo = 20
)

Also, for readability, I'd suggest changing the comment as I did below, on the line
Code: (Objective-C)
foo = 20;

Code: (Objective-C)
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    __block int foo = 10;
   
    void (^printFoo)(void) = ^(void) {
        NSLog(@"foo = %i",foo);
        foo = 20; // ** THIS LINE GENERATES A COMPILER ERROR WITHOUT THE __block MODIFIER
    };
   
    foo = 15;
   
    printFoo();
    NSLog(@"foo = %i",foo);

    [pool drain];
    return 0;
}
Logged
skochan
Administrator
Hero Member
*****
Posts: 3103







« Reply #1 on: September 18, 2011, 05:32:43 PM »

Hi,

THanks for your post.  This error has been previously noted in the Errata for the first printing and has been fixed in the second printing (that's the second printing of the 3rd edition).

Cheers,

Steve
« Last Edit: September 18, 2011, 05:34:41 PM by skochan » Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.