C compilers and standards help
Results 1 to 5 of 5

Thread: C compilers and standards help

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    161

    Talking C compilers and standards help

    Hello: I have always programmed in C for windows using either Turbo C or Borland C++.
    Recently I am trying to dive into the Mac OSX/Unix world. I am learning how to use the gcc compiler in mac os x panther. The help files in apple's developer pages are not very concise, I have tried to look around for a very basic tutorial on gcc but no luck. Could anyone point me to a basic tutorial in this matter?

    I also would like to ask if anyone can explain to me what libraries, standards and functions are compatible with which compilers? For example:
    Code:
    #include <stdio.h>
    #include <conio.h>
    void main(){
    printf("hello");
    getch();
    }
    This works perfectly under windows when I use my Borland compiler. In mac os x I have tried to compile it:
    $c++ hello.c
    and it gives me a series of errors saying that it can't find conio.h and stuff like that.
    Where does mac os x store the .h files for C?


    Thanks
    J

  2. #2
    Senior Member
    Join Date
    Dec 2003
    Location
    Pacific Northwest
    Posts
    1,675
    johnnymier,

    My understanding of compliers is a little dusty, MSMittens, Tedob 1 and others, are more knowledgeable with gcc questions than I am. Hopefully one of the Senior folks will jump in before I mislead you.....lol

    But I was interested to say the least. So I took a look at my software and it supports the following”C” Headers:

    C89: assert.h, ctype.h, errno.h, float.h, limits.h, locale.h, math.h, setjmp.h, signal.h, stdarg.h, stddef.h, stdio.h, stdlif.h, string.h, time.h

    Added with C99: complex.h, fenv.h, inttypes.h, iso646.h, stdbool.h, stdint.h, tgmath.h, wchar.h, and wctype.h

    And with C++, it includes the whole C library, however the C++ Headers do not necessarily indicate a filename. Example: vector, fstream, iostream, etc.

    With some compliers it may be necessary to drop the file extention to get it to work. If you used assert.h it would become <cassert> (the c representing “C” library)

    In the case you have listed: try using <cstdio> and <cconio> after the #include directive.

    #include <cstdio>
    #include <cconio>

    Please let me know if it works or if I’m just blowing smoke….lol

    Hope I have been some help


    cheers



    edit: Check out this thread by SonofGalen. I guess I wasn't to far off track..


    http://www.antionline.com/showthread.php?s=&threadid=25


  3. #3
    Senior Member
    Join Date
    Jul 2002
    Posts
    339
    Try this: http://www-ccs.ucsd.edu/c/

    Note:
    - There are other C Reference pages on the Net, but being the Standard C, that's my favorite.
    - "C Standard" here corresponds to ANSI X3.159-1989 or ISO/IEC 9899:1990.
    - As you can read yourself, (1) conio.h is not the standard C header file, (2) you only need to include stdio.h, and (3) you need getchar() not getch().

    Peace always,
    <jdenny>
    Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
    I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds


  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    161
    Ok This is the steps I am folllowing in order to compile and run a C program in macosx:
    write the code:
    Code:
    #include <stdio.h>
    int main()
    {
    printf("hello\n");
    getchar();
    return (0);
    }
    Compile it by typing in the shell: $c++ hello.cpp
    I get no errors.
    The I run It: $./hello.cpp
    I get two errors:
    ./hello.cpp: line 2: syntax error near unexpected token `('
    ./hello.cpp: line 2: `int main()'

    What am i doing wrong, thanks
    J

  5. #5
    Senior Member
    Join Date
    Jul 2002
    Posts
    339
    To compile a .cpp source program using gcc, do this:

    $ gcc -o hello hello.cpp

    this will save the compiled executable as hello in current directory

    Then run the executable like this:

    $ ./hello

    Note:
    Borland C and Turbo C DO have the command line version of C/C++ compiler (bcc/bcc32 for Borland C and tcc for Turbo C). You can compile your program like this:

    D:\> bcc32 hello.cpp

    This will save the compiled executable as hello.exe in current dir
    Then run the executable like this:

    D:\> hello

    So I guess it's not a Windows vs MacOSX problem, but rather a GUI vs CLI "problem".

    Peace always,
    <jdenny>
    Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
    I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides