0

I have a Console application with Xcode 4.2.1 and the keyword @autolreleasepool is not compiling: Compiler error The compiler seems to be set properly for my Console application: Project build settings Do you have any suggestion? I want to understand why the new keyword doesn't work if I have Xcode 4.2.1, I know how to write the autoreleasepool using the old syntax.

UPDATE

This is code that does not compile

#include <CoreFoundation/CoreFoundation.h>

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

        NSMutableArray *array;
        array = [[NSMutableArray alloc] init];
        int i;
        for (i = 0; i < 10; i++) {
            NSNumber *newNumber =
            [[NSNumber alloc] initWithInt:(i * 3)];
            [array addObject:newNumber];
        }
        for ( i = 0; i < 10; i++) {
            NSNumber *numberToPrint = [array objectAtIndex:i];
            NSLog(@"The number at index %d is %@",  i, numberToPrint);
        }

    }
    return 0;
}
Raffaeu
  • 6,694
  • 13
  • 68
  • 110
  • Have a look at the line above. Have you missed a terminator, or does something look wrong? This message sometimes pops up because it's interpreting the current line as part of the line above. – Abizern Jan 02 '12 at 17:46
  • I've just run that, and it compiles and runs just fine on my machine. – Abizern Jan 02 '12 at 18:25
  • @Abizern can you please tell me what is the setting of your main.c file? I have File type: default - C source – Raffaeu Jan 02 '12 at 18:27
  • I found the issue! Instead of creating a command line project with a Type = "Foundation" I used Type = "Core Foundation". I changed that to "Foundation" and now it compiles! – Raffaeu Jan 02 '12 at 18:29

2 Answers2

1

I found the issue! Instead of creating a command line project with a Type = "Foundation" I used Type = "Core Foundation". I changed that to "Foundation" and now it compiles!

Raffaeu
  • 6,694
  • 13
  • 68
  • 110
0

Is ARC enable for this file? Check both the project / target level settings and the individual compiler flags for the file.

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
  • Yes it does, both file and project are configured using ARC, i do not understand why it does not compile – Raffaeu Jan 02 '12 at 17:42
  • 1
    Then it might help to show a slightly larger snippet of code - the error might be before the @autoreleasepool statement. – Frederick Cheung Jan 02 '12 at 17:49
  • I have a Cocoa app and if I use the @autoreleasepool keyword it works perfectly, it also popups from the intellisense, in this Console application, in the .c file, it doesn't. ??? – Raffaeu Jan 02 '12 at 18:23
  • ARC is not required for `@autoreleasepool`, just the LLVM Compiler 3.0: http://stackoverflow.com/questions/7950583/autoreleasepool-without-arc – Brad Larson Jan 03 '12 at 17:35
  • Cool! Learn something everyday – Frederick Cheung Jan 03 '12 at 18:19