Objective C question - for loop

Discussion in 'Mac Programming' started by Fender2112, Feb 4, 2006.

  1. macrumors 6502a

    Fender2112

    Joined:
    Aug 11, 2002
    Location:
    Charlotte, NC
    #1
    Here's the code. A simple use of a for loop.

    The book I'm reading says that "for (int n = 1; n <= number; n++)" is a valid way of declaring and initializing a variable. There is also a footnote the says "This is a feature added to the 1999 ANSI C Standard (sometimes referred to ad C99). If you're using gcc and you get an error trying to use this feature, try adding the -std=c99 option to the command line."

    I do get an error and I'm using gcc via Xcode. Is there a #import or something else that adds this feature to Xcode without having to use Terminal?
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    This is not Objective-C! It's just C!

    You could simply move the loop variable defn so it works:

    int n;
    for (n=1;....
     
  3. thread starter macrumors 6502a

    Fender2112

    Joined:
    Aug 11, 2002
    Location:
    Charlotte, NC
    #3
    This I know. I more curious to know how to access this feature with Objective C. It works fine with C++, which is where I learned it and have gotten used to using it.

    I assume there is a header file that can add this feature to Objective C. If not I will have to go back to counting on my fingers and toes. :D
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I seem to remember that Apples version of GCC turns this off for .m (Obj-C) files. Just learn to live without it! You could try the setting above and pass custom arguements to the compiler. I'm fairly sure you can't add language features like this in a header.
     
  5. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #5
    Get info on the project in Xcode, and change the compiler dialect option to C99.
     
  6. thread starter macrumors 6502a

    Fender2112

    Joined:
    Aug 11, 2002
    Location:
    Charlotte, NC
    #6
    That's what I needed.
    Thanks
     

Share This Page