Previous 1 2 Next 18 Replies Latest reply: Jul 12, 2008 4:45 PM by Alonso Delarte
Fios89 Level 1 (5 points)
Hi! im interested in learning C.. but i dont know how to run GCC on OS X.. I think i installed it but how do I run it? or if i do it through Xcode.. how do I make a C file?

MacBook, Mac OS X (10.4.10)
  • Brian Postow Level 1 (40 points)
    It depends on what you're trying to do.

    If you're trying to create a mac application with buttons and slides and whistles, you run xcode, create a project and work from there.

    If you're just trying to write a program that will spit out the first 100 primes or something, (hello world, 100 bottles of beer on the wall, whatever) then I'd recommend picking an editor (vi, emacs, pico, textedit, whatever) coding up a file that ends in .c and saving it. (say foo.c)

    Then you go to the Terminal (under utilities) at the terminal you cd to where your file is (probably: cd Documents) and type gcc -o foo foo.c

    that will create an executable called foo which you can run by typing foo at the next prompt.

    I'm not sure what your or C knowledge is, so if that was at the wrong level, I'm sorry
  • Tod Kuykendall Level 4 (2,270 points)
    The best way to install gcc is to install the developer tools from Apple. Even if you don't want to use Xcode or the other tools it will install gcc and make all the necessary arrangements for it to work.

    If you want to use gcc to compile your C from the command line then use Terminal to gain access to the command line and use just about any C tutorial that is designed for Unix. A capable text editor like TextWrangler will be a big help eventually as well.

    Here's an OS X specific tutorial:

    This site has a lot of good tutorials for the beginner on it.

    Hope that helps,

  • Fios89 Level 1 (5 points)
    Well im not sure what I want to do.. I got this book called The C Programming Language Second edition cuz someone i know told me C is an excellent start to programming. I have a little experience in doing Java.. and I like HATE IT... So Id like to learn like C in general.. eventually id like to make apps for mac but i figure Id use cocoa with objective C for that.. for now I just want to learn C and i wasnt sure how to go about it.. but my friend told me GCC is good
  • xnav Level 5 (6,635 points)
    Install the Developer Tools, then follow [this|] to get started.
  • Fios89 Level 1 (5 points)
    Thanks much
  • etresoft Level 7 (27,838 points)
    Fios89 wrote:
    I have a little experience in doing Java.. and I like HATE IT...

    What don't you like about Java. I'm not trying to start a Java-bashing thread, I just want to find out what kinds of programming you would like to do. There are lots of languages, architectures, and paradigms to choose from.

    So Id like to learn like C in general..

    While C and Java are very different beasts, there are some other critters that you might like better. I wrote C and C++ for 15 years, but I wouldn't touch them today. I use Perl and Objective-C/Cocoa now and I love it.

    What do you really want to get out of it? What kinds of software do you want to write?
  • Fios89 Level 1 (5 points)
    I dont mean to bash Java either.. but with what I have experienced with it.. I really dont like it and I find it confusing.. In terms of what I want to do with C? I really dont know.. Im in college right now a freshman.. and I want to become a software developer eventually.. maybe even for apple! So I guess I want to develop software apps? I dont wanna do things like hardware drivers or bios or stuff like that...
  • Brian Postow Level 1 (40 points)
    The odds of C being less confusing than java are slim, in my opinion... they basically have the same syntax. Java has more complicated data structures, but to a beginner, they look pretty much the same...

    Having taught both, I can say that Java is easier to teach, without a question, but YMMV.
  • xnav Level 5 (6,635 points)
    C is a procedural language, Java is an object oriented language. They require two different mind sets. For todays world and especially for Apple, I would recommend the object oriented mind set. Especially since you stated that you were interested in application level and not system level programming.
  • Fios89 Level 1 (5 points)
    That is true.. but from what I was told C is a great start and that I can use it to migrate into Objective C, and Cocoa with Objective C which are object oriented... and plus it cant hurt me to know a procedural language eh? I originally did Cocoa with Objective C so I got stuck.. so I figured id go down to the bare bones.. C since ObJ C is an extension of C.
  • Brian Postow Level 1 (40 points)
    Pedagogically speaking, C is a horrible language. It's like learning how to cut your food with the sharpest knife in the drawer. You give a sharp knife to a 4 year old, and you're going to get blood.

    C is the same. it's very easy to do something dangerous, and stupid. Java is to a large extent a duller blade.

    Java lets you shoot yourself in the foot.

    C hands you the gun and helps you aim.

    C++ hands you a bazooka aims it, and says "Please PLEASE blow off your own leg."
  • Fios89 Level 1 (5 points)
    Omg i want the bazooka! Lol.. anyway.. i really wanna just get eventually into Cocoa with Objective C unless theres some other Object Oriented Lang that I would want to get into.. I just need a starting point.. and I honestly dont like Java.. its too confusing for me I understood C and Cocoa more when I did them.
  • etresoft Level 7 (27,838 points)
    I think your book (which is the C book to have, by the way) combined with Brian's instructions on how to use GCC in the Terminal, should be good to get you started. That book isn't going to teach you how to do anything dangerous and would be a good knowledge to have. So I think you are on the right track. I apologize if I've started an unproductive tangent.
  • Fios89 Level 1 (5 points)
    Right right... so im assuming basically.. i just use like.. Text edit to actually script my program... then using terminal it executes it. Ok! Im ready for C! Thanks!
Previous 1 2 Next