C++ in Xcode?

Hello again... stupid Fios89.. I gave up on Cocoa atleast for now.. and now im teaching myself C++ using "Sams teach yourself C++ in 21 days".. Can I use Xcode to make C++ programs?

MacBook, Mac OS X (10.4.10)

Posted on Aug 19, 2007 8:10 PM

Reply
37 replies

Aug 21, 2007 5:26 AM in response to Fios89

Lol, a void function/method doesn't return anything, the compiler makes it return 0 but it doesn't mean anything. You're not supposed to recover the return value of a void function/method. void = nothing..., watch out it's different from "void *" which represents a pointer to any type of value.
However, function/method returning void are not supposed to be anywhere else than on there own line, like a setter for example :

[[myObject setValue: 5]];

No equal before it...

But do you know C language ? Or a language of the same family ?

Message was edited by: PsychoH13

Aug 21, 2007 6:11 AM in response to Fios89

Fios89 wrote:
I dont even still understand that a void function doesnt return a value. I dont understand that value thing..


If you ask specific questions like this, you are much more likely to get a meaningful answer. For example...

Modern computer architectures make heavy use of something called a stack. It is just what it sounds like, a stack of data. You can put something onto the top of the stack and you can remove the top element from the stack. That is all.

When a program wants to call a function, it will typically push all of its arguments onto the stack and then push onto the stack the number of arguments it just added. Then it will run the function. The function will remove the top element from the stack (the number of arguments). Then, it will remove that many arguments from the stack. That is how function arguments move from caller to callee.

When a function returns, it may, _or may not_, push its result onto the stack. The caller has to know from the function signature (void, int, object, etc.) just how much data to expect to find on the stack when the function completes.

Of course, there are a thousand and one ways to make this process more efficient, but this is the basic idea.

Please, don't ask for general help. People are just going to tell you to go read some book. If you read the right one, it might help. But it isn't likely that you will find it. Few people write books about or teach fundamentals anymore. If you do look for a book, make sure it was printed at least 30 years ago or it will confuse you with meaningless "current" technologies that won't exist next year. If you have a specific question - ask it. I don't know a chemical bond from a covalent dipole-moment, but I do know programming.

Aug 21, 2007 6:47 AM in response to etresoft

Thats my whole point though.. my goal was for me to just teach myself a language without bothering other people for help. And your saying a book printed 30 years ago? Wow.. Ive been looking for very recent books.. Theres a C book that was published in 1989 I guess I can use that? And LOL the chemical bond and dipole moment thing... funny. AP Chemistry was a nightmare for me. And to the poster before this one.. I only know a small amount of HTML and a tiny tiny bit of MS-DOS.

Aug 21, 2007 7:14 AM in response to Fios89

Fios89 wrote:
Thats my whole point though.. my goal was for me to just teach myself a language without bothering other people for help.


I certainly don't mind. I wouldn't be posting here if I weren't bored at work and looking for something to do.

And your saying a book printed 30 years ago? Wow.. Ive been looking for very recent books.. Theres a C book that was published in 1989 I guess I can use that?


You can if it is this book. I buy very few books. Most of them are only for beginners or are outdated or just wrong. It wouldn't be any better for a beginner, because then you would have to try to pick one of those. How do you choose? I pick the oldest, smallest, cheapest, and least flashy. I truly hate the ones that spend the entire book building some silly application that I don't need. They all try to be thicker than any of the others to give the impression you are getting more for your $55.

Here are my recommendations:
C Programming - the original (almost)
C++ - this specific revision, not the newer one.
How to use the C++ STL - pretty advanced, for future reference
Motif programming - nobody uses Motif, but if they wanted to learn, there is no other book.

And that reminds me. Marshall Brain (the author of the Motif book) has a big web site with a section specific to programming. Look at that. It might be useful.

Aug 21, 2007 8:20 AM in response to Fios89

Fios89 wrote:
That C book you recommended me is the one I picked out at barnes and nobles .com lol!


Good. Your goal really isn't to "learn C", but to learn how to program. C is a very fundamental language. C++ and Objective-C, and pretty much everything else is implemented using C, behind the scenes. Once you know C, and understand why and how it works, you can pick up most of the other ones easily.

Wait I have to learn C++ and Motif too? My ultimate goal is to be able to learn Cocoa. Those are also prerequesites?


No. That is just an example of how few books I think are worth mentioning. For example, I think the old Stroustrup C++ book is much better than the newer one.

Definitely don't bother with Motif. I'm not even sure you need to bother with C++. You probably do need to learn about Object-oriented software and design. But that isn't exactly C++'s strong suit. Objective-C is a much, much better OO language.

Aug 21, 2007 8:38 AM in response to etresoft

Oh.. ok. Well then thats what im gonna do! I was thinking of learning Carbon too but if I can manage with just Cocoa thats fine.. But more importantly first I have to get my Mac fixed.. I have to take it back to the store I got it from and see If I can schedule an appointment with a Mac Genius.. I called apple.. they are telling me It might be a hardware issue but I might want to format my drive using my OS X discs.. But Id rather not format it because if it is a hardware issue.. I want the Mac Genius to see the problem.. I ran techtool deluxe and it discovered that theres 1 error on m surface scan.. also Xcode wont run anymore and other stuff.. I think I got a bad mac lol! (is that possible?!)

Aug 21, 2007 9:47 AM in response to Fios89

From what you have described, it sounds like it could be a hard drive problem. Make sure your data is backed up.

You can't really blame a hard drive problem on Apple. Hard drives have really gone down in quality over the years (but also up in size and down in price). Hard drives these days only last 3 years or so. It sounds like yours may be DOA.

My recommendation would be the same as Apple's. Do a re-partition and reinstall. If the drive really is bad, the re-install will probably fail. Then, you can take that completely hosed machine back to the Apple Store with no hassles. That is what I do if I suspect the drive is bad. Sometimes it runs fine for another year, sometimes it dies during the re-install.

Aug 21, 2007 10:16 AM in response to etresoft

Oh im not blaming apple for this.. its completly impossible for any company to produce its product 100% every single time. But I should reformat it? I decided to take it to the store as is so they can see the problem as its manifesting instead of me telling them an abridged version of it. I just need it fixed before the 29th of august because I bought this for school.. Even if I wanted to reformat though that would be hard.. My drive doesnt always pick up my OS X disc.. the girl at apple said I need my laser recalibrated.. but its only less than a month old.

Aug 21, 2007 10:31 AM in response to Fios89

Fios89 wrote:
Oh im not blaming apple for this.. its completly impossible for any company to produce its product 100% every single time. But I should reformat it? I decided to take it to the store as is so they can see the problem as its manifesting instead of me telling them an abridged version of it. I just need it fixed before the 29th of august because I bought this for school.. Even if I wanted to reformat though that would be hard.. My drive doesnt always pick up my OS X disc.. the girl at apple said I need my laser recalibrated.. but its only less than a month old.


I have never heard of having a laser recalibrated. It sounds like they should give you a new machine. You have a dud.

Aug 21, 2007 3:36 PM in response to Fios89

Ok... I got that C Programming Language book you recommended.. Now I have acouple questions. One.. I can use Xcode for writing C programs? Ive tried using text edit but I cant save the extension as .c it wont let me.. Also.. this is for xcode in general.. any way I can install the entirety of the Xcode stuff including all the packages in 1 shot without having to do each one, one after another? More than less likely im going to have to start from scratch when my laptop problem is fixed and installing Xcode and all its packages takes a while when I have to click each one individually..

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

C++ in Xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.