PDA

Click to See Complete Forum and Search --> : C compilers and standards help


johnnymier
February 10th, 2004, 11:25 PM
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:

#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

Relyt
February 11th, 2004, 12:06 AM
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

jdenny
February 12th, 2004, 08:28 AM
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>

johnnymier
February 20th, 2004, 02:23 AM
Ok This is the steps I am folllowing in order to compile and run a C program in macosx:
write the 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

jdenny
February 20th, 2004, 08:03 AM
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>