The C Programming Guide and xcode

Discussion in 'iOS Programming' started by FreeLunch1, Oct 31, 2008.

  1. macrumors member

    Joined:
    Jun 9, 2008
    #1
    In the wiki it states
    "The standard reference book for C is "The C Programming Language" by Kernighan and Ritchie. There are also many online references to help you get started. In OS X you can use XCode or command-line tools such as gcc to build and run your C programs. "

    Is there a guide somewhere that tells you how to use xcode to compile C programs and run them?
     
  2. macrumors member

    Joined:
    Aug 24, 2008
    Location:
    Austin, TX
    #2
    The standard reference book for C is NOT K&R, it is Harbison and Steele, "C: A Reference Manual", the latest (5th?) edition. K&R is hopelessly out of date. Come to think of it, H&S is an excellent read.

    Doug
     
  3. macrumors 6502

    Joined:
    Jun 21, 2008
    #3
    Bigger question is why are you writing in C on the mac? Because you need to (school?) or because you think you want to learn C. Most Mac + iPhone stuff is written in Objective C (not the same thing)....
     
  4. macrumors member

    Joined:
    Jun 17, 2008
    #4
    A strong background in C helps you learn Obj-C, although you can learn Obj-C from scratch. Either way, most of the base-level stuff is the same, except with Obj-C you come across pointers much sooner. The next edition of Kochan's book would be best: it does teach Obj-C with no expectation of any C experience.
     
  5. macrumors member

    Joined:
    Aug 24, 2008
    Location:
    Austin, TX
    #5
    Objective C IS C, but re-interpreted as an object-oriented language. The mechanics are the same, but in disguise.

    A few extensions. It's amazing how this throws people. Read Brad Cox, this guy was a revolutionary genius IMO. Look what's happened.

    Doug
     
  6. thread starter macrumors member

    Joined:
    Jun 9, 2008
    #6
    From the programming wiki on this site, it recommended "The C Programming Book" I figure it can't hurt to learn C and use that as a base to learn Objective C. Then I'll learn more about Cocoa, etc..

    So, back to my question, is there a guide out there showing how to compile C programs in xcode?

    thanks again...
     
  7. macrumors member

    Joined:
    Aug 24, 2008
    Location:
    Austin, TX
    #7
    Sigh... Are you referring to K&R? Again, that's obsolete. It barely covers ANSI C, it's 20 years old, the new standard is C99. It amazes me that people still recommend K&R anymore, although nobody ever lost their job from doing it. Instead of Beowulf, try Kochan's book on C (not the book on Objective C.) It will tell you everything you need to know about C. For writing console programs in C in Xcode, to learn that language, there's very little you need to know about the plumbing of Xcode. Apple's online Xcode documentation should cover that much, or look over the first chapter of Kochan's old Objective C book in the bookstore.

    Doug
     
  8. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #8
    Err no.

    K&R 2nd Edition is still the standard C text. Every C programmer should own it. No questions asked.

    The fact that most compilers do not support C99 mean it is still completely in date.
     
  9. macrumors member

    Joined:
    Aug 24, 2008
    Location:
    Austin, TX
    #9
    Let me put this more gently to you: I own K&R, and I learned C from the first edition. I also own the second edition. Back in the day, that was all we had. I would feel sorry for anyone learning C from K&R today, when there are much better tutorials out there, both in expository completeness, coverage of new and standard features introduced in the last 20 years, and clarity about the limitations and "dark corners" of the language.

    Your comment about K&R being "completely in date" is bizarre and misleading.

    Doug
     
  10. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #10
    You said it was out of date. I corrected you. The 2nd edition covers ANSI C or C89 which ever name you prefer. That is the dialect of C that 99% of C books teach. It is in date. There is nothing that it teaches that is out of date.

    Sure it does not teach you the features of C99 but then just because you don't know about VLA's does not mean that the old static arrays are suddenly old hat.

    It is an extremely concise book that teaches the language in a very effective matter. Including areas that other books just skim past.
     
  11. thread starter macrumors member

    Joined:
    Jun 9, 2008
    #11
    My intention was not to create a debate on C books, but simply,

    is there a guide or reference out there showing how to compile C programs in xcode?

    As far as books, I purchased the C programming guide and will be using it since I own it. Along with other web materials, books, etc, I hopefully should get down the path.
     
  12. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #12
    If you are just learning you are better off using the command line rather than using Xcode.

    Xcode just adds a whole level of unnecessary complexity that you don't really need to know at the moment.

    All you need to know is described in The C Programming Language 2nd Ed. Just change any instance of cc to gcc when it talks about typing in a command.

    For instance the first exercise says type cc hello.c and then a.out to run.

    You'll probably want to do something like gcc -o hello hello.c and then run the code by typing ./hello.

    That is all you need to know pretty much for now.
     
  13. macrumors member

    Joined:
    Aug 24, 2008
    Location:
    Austin, TX
    #13
    Well, my intent was not to provide an introduction to Xcode, but simply to point out that the wiki book recommendation gave you the wrong idea.

    But while I'm here... (scans bookcase idly...) if you really want to be led down the garden path with Xcode, there is a book called "Beginning Mac OS X Programming" by Trent et al, that not only holds your hand, it s... oh never mind.

    BTW Mr. Cromulent, perhaps I gave you the teh wrong idea. I LOVE K&R. I think it's one of the masterpieces of tech literature. Are you by any chance also a fan of Radiohead?

    Doug
     
  14. macrumors 68040

    Joined:
    May 29, 2003
    #14
    a good example of making all the wrong choices.

    This is a highly debateble suggestion! If the focus is on learning C quickly a good IDE with good integration with a debugger and editor can be helpful. It doesn't take care of the finer details involved in building software but those details can tend to get in the way.
    I tend to disagree, as above good IDEs can be very good learning environments. A reasonable question would be is XCode a good IDE!
    This I believe is your worst piece of advice but is to be expected from someone who thinks America made the right choice. Basically it indicates that you prefer to prepare for the past rather than the future. Like it or not K&R is basically worthless for a student new to programming.
    Yep and you carefully left out several issues that the learner wouldn't have to deal with in an IDE.
    Haha
     
  15. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #15
    True. It is debateable. I just gave my opinion.

    I disagree strongly with your assertion.

    Not really as you spend time learning the IDE rather than learning the language and the tools which can be used across platforms (the command line).

    Wow you managed to bring politics into a programming discussion. How clever of you!

    What is your point about the past? The C Programming Language is still relevant today and has nothing to do with the past. It is an old book, yes. I guess you're one of these morons who thinks we should stop teaching Shakespeare because it is too old fashioned.

    Like learning a tool which only works on one platform? Like having to find out how to set all the compiler flags in the IDE? Like finding out how to link libraries?

    All of which are trivial on the command line but actually need to spend time arsing around learning with an IDE.
     
  16. macrumors 68040

    Joined:
    May 29, 2003
    #16
    Hopefully this will be helpful.

    I understand this but I have to agree with the posters here that see K&R as bad advice. I'm not sure what your age is but if you are a young person it does you no good at all to learn about C with a more than 20 year old dialect.
    I don't know of any that specific but it isn't that hard to get up to speed with XCode. You just need to be willing to play around a bit and realize how things are accomplished in XCode.

    First:
    Understand that things are accomplished in XCode via projects. So your first task is to create a project. XCode supports several types of projects, you need to create one best suited to the book you are using. Most likely you will want to create a "Command Line Utility" of the "Standard Tool" type.

    Second:
    If you did as such you should sees XCode project window pop up. In that window look for a file called "main.c". You can single click on that to bring up a editable file in that window. Click on the "Build and Go" icon and the program should compile and run.

    Third:
    The bad part about XCode is that you need to bring up a console window to see the program output. The console can be found in the Run menu.

    Fourth:
    What you would have done above was to compile and run a program that was canned. Obviously to learn C you need to start editing that program. Here you would follow whatever text you are working from.
    Err be careful with web resources, some are really bad! The whole point of choosing a good text is to learn the right way to do things. Pick up the wrong habits and you might have trouble especially when it comes to growing into other languages. Not to promote other web sites but you might want to offer up the same question on ARSTECHNICA 's forums. Specifically about the use of XCode and the texts you believe are reccomended.

    By the way everytime these questions come up the discussion often degenerates into two camps. One reccomending command line tools the other IDEs such as XCode.

    I'm going on reccord as saying you are far better off with a good IDE! That however doesn't mean that you don't need to know or understand the command line environment. I actually believe these tools are very important to understand in this way, however that is a separate issue entirely from learning C. A good IDE in my mind is a better place to learn the mechanics of a language.


    Dave
     
  17. macrumors 68040

    Joined:
    May 29, 2003
    #17
    Interesting but misplaced concerns!

    Maybe you will come around but hopefully some of my other postings will clear up what I'm trying to get at. The nice thing with MacOS/X is that either approach will work but I do believe it takes more effort to get an environment set up for command line use.
    I have a hard time accepting that if you are serious about getting someone new to programming up to speed. With an IDE they can be run program within seconds after the installation.

    Now I'm not going to disagree with the need to learn command line tools. There are a lot of good reasons to know what they are and how to use them. The problem is none of those reasons have anything at all to do with learning C. I believe that the introduction of such tools detracts from what the poster wants to focus on.
    Just responding to the message out of your profile. To be honest though I think America is about to plunge into it's darkest years ever and many people will quickly regret voting for Obama. It is a huge shame on the part of the Democrates as the could have won with just about anybody, instead we now have somebody so far left of center that no reasonable person will be able to trust him.
    Your reccomendation has everything to do with the past! It is very poor form to suggest to a new programmer that they learn a version of C that is simply not up to date. Especially if said programmer expects to have any sort of future for himself!

    Look at it this way if you have a new project that requires a new programmer and you had a choice between one that sort of knows K&R and one that knows the latest standard C and the proposed extensions, which would you hire?
    Actually just the opposite, I even have Shakespeare on my iPhone! The problem I have is with people, like you, that want to regress 20 years and not acknowledge that the world changes and along with it programming languages.
    See this is where you need to grab that cup of coffee and wake up. This thread is about learning a tool but rather a programming language. The original poster has even tried to pull the thread back on track. Your problem is that you can't separate the language from the tools, they are two distinct things.
    That is total BS! The problem here is that I think you know this and are just trying to confuse the original poster. So what is your problem then?


    Dave
     
  18. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #18
    Install Xcode. Command line tools work. Pretty easy setup.

    See above, same holds true of the command line.

    One way or the other the OP needs to learn some tools. Better to learn the compiler directly than some abstract that only applies on Mac OS X machines.

    To be frank, I don't give a damn about your political beliefs.

    Considering there is only perhaps 1 or 2 fully C99 compliant C compilers available and every compiler under the sun complies with C89 I know which I think is more relevant to learn for a beginner.

    The one who can program well. Oh and you do know there is a second edition of K&R don't you that covers ANSI C?

    Who was it that started talking about politics? Right, so don't lecture me about getting off topic in a thread.
     
  19. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #19
    There's a lot of Objective-C stuff on youtube that you might find interesting/useful. I must admit though I've not actually managed to watch 1 video all the way through without falling asleep.

    b e n
     
  20. thread starter macrumors member

    Joined:
    Jun 9, 2008
    #20
    Well I don't think I ever found exactly what I was looking for, however, I do know how to get several people pissing on each other! :)
     
  21. macrumors member

    Joined:
    Aug 24, 2008
    Location:
    Austin, TX
    #21
    I already told you exactly what you were looking for: Kochan's C book, and the Trent book. If those don't satisfy you, you are one tough customer.

    Doug

    Just say, IP on everything. Etc.
     
  22. macrumors 68040

    Joined:
    May 29, 2003
    #22
    Misunderstandings

    I don't think the majority of this thread knows what you are looking for! As to me I think I do but frankly really haven't seen anything that really gets you started with XCode.

    You don't really need to worry to much about that as XCode is fairly easy to grasp. If you haven't installed it already do so and go through the documentation. You might want to consider the most recent version which is 3.1.1 as it has the most recent documentation.

    As to actually building your first program the message I posted earlier will get you started. Best of luck and I hope you find all the time you need to proceed. Time seems to be an issue for me right now ;)

    Dave
     
  23. thread starter macrumors member

    Joined:
    Jun 9, 2008
    #23
    thanks for the input guys.. I appreciate your help..
     
  24. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #24
    Have you checked out the iPhone SDK video tutorials (Apple's own, iphonedevcentral.org's, and other site's)? They show how to run XCode.
    Some intro Obj-C as well.

    .
     

Share This Page