Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

anmldr

macrumors member
Original poster
Jul 14, 2008
65
0
Newbie to Mac, ObjC, Xcode, etc. Background more in Palm and other PDA programming using Visual Basic like languages.

I would like to simply write a Hello World app in C and compile it. I am not sure what tools are available.

I do have Smultron as a text editor. If I write the code in Smultron and save it as hello.c then I use Terminal and enter gcc -o Hello hello.c I get an error that is "return type of ‘main’ is not ‘int’"

Code:
#include <stdio.h>

void main()
{
	printf("Hello, World\n");
}

I need suggestions for if the route that I am using is best to get a start in C on an Intel Mac and any other guidance that you offer.

Thanks,
Linda
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
you are on the right track. Just switch
Code:
void main()
To
Code:
int main(int argc, char *argv[])

You are well on your way to recovery from BASIC. Good luck!

-Lee
 

kpua

macrumors 6502
Jul 25, 2006
294
0
FYI, the argc and argv arguments are not needed. It is perfectly fine to leave them off. It's a common misconception that they are required.

(A little known fact is that even when you specify both argc and argv, you're still leaving one argument off. There's a "char **env" argument that contains a list of all environment variables.)

But, the return type must be int in C, because the parent process uses it to get the exit status.
 

Cromulent

macrumors 604
Oct 2, 2006
6,816
1,101
The Land of Hope and Glory
FYI, the argc and argv arguments are not needed. It is perfectly fine to leave them off. It's a common misconception that they are required.

(A little known fact is that even when you specify both argc and argv, you're still leaving one argument off. There's a "char **env" argument that contains a list of all environment variables.)

But, the return type must be int in C, because the parent process uses it to get the exit status.

But if you do leave argc and argv off, you must put void in its place otherwise you stray into implementation specific territory.
 

anmldr

macrumors member
Original poster
Jul 14, 2008
65
0
But are Smultron and Terminal the way to go to get my feet wet in learning C? Or are there better options? I just need to have a little background in C, then move onto C++ for a short while before REALLY diving into ObjC and iPhone programming. Every book and article or other source for iPhone development start out saying that you need a background in C and an object oriented programming environment like C++. I did take a college course years ago in C++.

Pet peeve of mine :) Why doesn't someone write a complete beginner book on Xcode, ObjC and Interface Builder that introduces the concepts needed? Instead, all of the books, tutorials, videos, etc. assume that you have a background in other languages.

I was able to pick up other programming languages for the Palm and Windows Mobile environments without first having a background in coding for the desktop environment. I would like to port some of my other PDA apps to the iPhone....knowing they will be quite different on the iPhone. But, having to learn 2 other languages BEFORE learning ObjC is a pain. Diving into ObjC without any background in C/C++ would be preferable to me.

Oh well. I am off to do my homework.

If you have a suggestion for a book that is now available that would help me as a beginner to ObjC without first leaning C and brushing up on C++, I would appreciate it.

Linda
 

MrStevieP

macrumors newbie
Feb 27, 2008
22
0
FYI, the argc and argv arguments are not needed. It is perfectly fine to leave them off. It's a common misconception that they are required.

(A little known fact is that even when you specify both argc and argv, you're still leaving one argument off. There's a "char **env" argument that contains a list of all environment variables.)

But, the return type must be int in C, because the parent process uses it to get the exit status.

If you check the wikipedia for Main Function, you'll also find that on Mac OS X you can have a fourth parameter for OS related stuff.
 

mobilehaathi

macrumors G3
Aug 19, 2008
9,368
6,353
The Anthropocene
But are Smultron and Terminal the way to go to get my feet wet in learning C? Or are there better options? I just need to have a little background in C, then move onto C++ for a short while before REALLY diving into ObjC and iPhone programming.

Everyone will have their own opinion on this. I learned C++ on the command line with emacs, gcc, and make, and I wouldn't have it any other way. I would stick to what you're doing, since you'll probably pick up a good understanding of a lot of what goes on underneath an IDE anyway. Eventually, I guess, you'll pick up Xcode and do your iPhone programming in that. I haven't programmed for the iPhone (yet!), but I get the impression things are nicely streamlined within Xcode (and IB?) to allow for quick work on some of the more tedious bits.

Best of luck!
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
Pet peeve of mine :) Why doesn't someone write a complete beginner book on Xcode, ObjC and Interface Builder that introduces the concepts needed? Instead, all of the books, tutorials, videos, etc. assume that you have a background in other languages.

They have! Unfortunately, it hasn't yet been updated in a while. Still, the first ~ half of the book is the beginners guide for the Objective-C language you are looking for that does not assume prior experience with other languages.

It does not cover Objective-C 2.0 features, the massive changes to Interface Builder, or the changes to Xcode. But you will get a good understanding of Objective-C and Cocoa memory management techniques (since you can't use garbage collection for iPhone development, you'll need to know this).

There's a new version of the book in the works, but I'm not sure when it's coming out: http://www.amazon.com/Programming-O...=sr_1_2?ie=UTF8&s=books&qid=1220453293&sr=1-2
 

ChrisA

macrumors G5
Jan 5, 2006
12,919
2,172
Redondo Beach, California
But are Smultron and Terminal the way to go to get my feet wet in learning C? Or are there better options? I just need to have a little background in C, then move onto C++ for a short while before REALLY diving into ObjC and iPhone programming.

Yes. Start with the terminal and a text editor. Write some simple, non-graphic text oriented stuff. Then move on to using Apple's xcode. But write now you don't need to try to learn both xcode and C at the same time.

I typicaly have 4 to 6 terminal windows and a few editor sessions up at once. I pretty much leave them up for days at a time. The code I write has to be portable to other *nix OSes.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I definitely think that a text editor for writing code, gcc for compiling and linking code, and gdb for debugging are the way to go starting out. You will get a better idea of what's really going on, and won't have everything hidden away from you by the IDE. For C there's very few times that code completion actually comes into play (i guess for structure elements... i don't know if XCode does this for you or not), and to me that's one of the best parts of using an editor in an IDE.

I would say that C is a fine place to start... i don't know that you need to learn OOP concepts before starting Objective-C, though. I think it would be fine to learn OOP with the object model provided by objective-C. You'll miss out on some things like multiple inheritance, but I think you'll get by OK without that. If you move to a language that supports multiple inheritance after learning OOP with Objective-C, it shouldn't be hard to pick up.

-Lee
 

anmldr

macrumors member
Original poster
Jul 14, 2008
65
0
They have! Unfortunately, it hasn't yet been updated in a while. Still, the first ~ half of the book is the beginners guide for the Objective-C language you are looking for that does not assume prior experience with other languages.

There's a new version of the book in the works, but I'm not sure when it's coming out: http://www.amazon.com/Programming-O...=sr_1_2?ie=UTF8&s=books&qid=1220453293&sr=1-2

Thank you! I had already ordered the next edition when it is released...not knowing anything about the book really except for it's title and author. Now that you recommended it, I went ahead and ordered a used book and will get working with it until the new edition is released.

There are LOTS of new iPhone developer books coming out soon. I guess the holdup is the NDA. I have many of these preordered as well.

I am a recent Mac convert. I do love my Macbook and am enjoying learning to program for it.

Actually, I am an old and new Mac user. I owned the second Mac made...the 512K "portable" computer. I still have it and it probably still works. I need to find a museum somewhere probably to donate it to :)

Linda
 

anmldr

macrumors member
Original poster
Jul 14, 2008
65
0
Have been coding most of the day using Smultron and Terminal. Everything seems to be working great.

Thanks for your help.
Linda
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.