C standard (ANSI, C99, etc) in objective C

Discussion in 'Mac Programming' started by akabeer1983, Jan 7, 2009.

  1. akabeer1983 macrumors newbie

    Joined:
    Jan 7, 2009
    #1
    H, i am new to objective C. I learnt tat C is a subset of Obj C. So which standard of C (ANSI C, C99, ISO C, etc) is implemented in obj c?
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    Good question. As Objective-C is really just a layer on top of the C compiler it depends on the C compiler being used I believe.

    In the case of Macs that means that the compiler has limited support for C99 and full support for C89 (otherwise known as ANSI C). More information on GCC support for C99 can be found here (assuming you are using GCC 4.2 to compile your projects) or here if you are using GCC 4.0.1 to compile your projects.
     
  3. akabeer1983 thread starter macrumors newbie

    Joined:
    Jan 7, 2009
    #3
    Hi, Thanks for the reply. I am using XCode to learn Obj C. In that I create an empty project and add a new target file specifying cocoa application. I double-clicked and opened the target file and there i also specifed
    " -std=C99 "
    in the C Language Dialect.

    However, i am learning to develop for iPhone. So I am confused over which standard of C should I use.
    Can anyone help me.
     
  4. akabeer1983 thread starter macrumors newbie

    Joined:
    Jan 7, 2009
    #4
    One more doubt. Suppose i am writing a program (say an algorithm for arranging numbers in ascending order) in ANSI C and C99 standard. After writing the code, i compile and create the exe files for both programs, say EXE1 and EXE2.
    Now the question is "if EXE1 runs on a machine/OS/platform , then is it guaranteed that EXE2 also runs on the same machine/OSplatform?"
    I think though they may be coded in different standards of C, their EXE files are only binary code, so both EXE1, EXE2 can run on the same machine/OS.

    Assume the following statements to be true:
    Program 1 (coded in) ANSI c (compiled to) EXE 1 (runs on PLATFORM 1)
    Program 2 (coded in) ISO c (compiled to) EXE 2 (runs on PLATFORM 2)
    Program 3 (coded in) C99 (compiled to) EXE 3 (runs on PLATFORM 3)
    .
    .
    .
    Prog N (coded in) standard N (compiled to) EXE N (runs on PLATFORM N)

    If PLATFORM 1 = PLATFORM 2 = . . . .PLATFORM N,
    then does the above statements are still true?
     
  5. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #5
    A language standard doesn't have anything to do with the platforms the final code will run on.

    A compiler takes text, and produces CPU-specific instructions. The linker will produce a platform-specific binary (since each platform usually has a different wrapper around the CPU instructions).

    Any language can be compiled for any platform as long as the compiler supports it. Picking C99 or C89 won't make a difference. Using Win32 APIs to produce an EXE instead of using say, POSIX and a Mach-O binary will change what platform it can run on (as will compiling for PPC, versus x86).
     

Share This Page