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

Futhark

macrumors 65816
Original poster
Jun 12, 2011
1,237
175
Northern Ireland
This might sound silly but it's a question I don't know the answer to :) I'm learning C and I've written several basic math program's, I've learned to compile them using GCC

I type GCC myapp.c -o myapp and it compiles it and creates the program for me. If I want to share my app with friends to test is it the file it creates I send? Does it matter if they are MAC or PC users or does it not matter? I know on a mac terminal opens the program so if it works on a PC what runs it?

As a mac user will all my apps I write in C only open in terminal or will I be able to create an independent app that runs outside of terminal? Something when opened say will open a window with my app running?

I hope I've explained this ok lol :) I know what I'm trying to ask for but not sure I've worded it well enough for you to understand hehehehe Fingers crossed I have.
 

robvas

macrumors 68040
Mar 29, 2009
3,240
629
USA
If you compile a program on a Mac, it's only going to run on a Mac. Same goes for Linux or Windows. You could send them the source code and they could compile it themselves, though.

Other languages such as Java have the goal of 'write once, run anywhere'.
 

macuser1232

macrumors 6502a
Jan 20, 2012
668
4
This might sound silly but it's a question I don't know the answer to :) I'm learning C and I've written several basic math program's, I've learned to compile them using GCC

I type GCC myapp.c -o myapp and it compiles it and creates the program for me. If I want to share my app with friends to test is it the file it creates I send? Does it matter if they are MAC or PC users or does it not matter? I know on a mac terminal opens the program so if it works on a PC what runs it?

As a mac user will all my apps I write in C only open in terminal or will I be able to create an independent app that runs outside of terminal? Something when opened say will open a window with my app running?

I hope I've explained this ok lol :) I know what I'm trying to ask for but not sure I've worded it well enough for you to understand hehehehe Fingers crossed I have.
umm why use gcc when you have Xcode or Code::Blocks?
 

Futhark

macrumors 65816
Original poster
Jun 12, 2011
1,237
175
Northern Ireland
If you compile a program on a Mac, it's only going to run on a Mac. Same goes for Linux or Windows. You could send them the source code and they could compile it themselves, though.

Other languages such as Java have the goal of 'write once, run anywhere'.

That's good to know thanks. So when I write my small program's are they destined to only be opened in terminal?
 

ghellquist

macrumors regular
Aug 21, 2011
146
5
Stockholm Sweden
That's good to know thanks. So when I write my small program's are they destined to only be opened in terminal?

Yes, and no. It sort of depends.

When you write "bare" C programs they rely on a library of standard functions. These functions include allowing you to write characters to the terminal using printf, getting characters from the terminal, connecting to an internet port and so on. These functions are more or less the same on the source code level on just about any operating system or computer today, thanks to standardisation. Incidentally the c-compiler more or less automatically includes these functions, but in c you still need to #include <stdio.h> or other functions. ( By the way, it is quite interesting to try to understand what happens in stdio.h, beware that it has some quite advanced concepts ) .

But the standard c libraries will not allow creating windows or getting events when you mouse click on a button or pinch with your fingers on an iPad, just two of many examples. These functions requires you to use other libraries. These libraries are very different on different operating systems: quite different on OSX compared to Windows 7 as one of many examples.

The difference between different operating systems when it comes to "windows" makes it quite difficult to write programs that work in several environments ( several Os-es ) . What the big guys does probably do is to divide the program into two parts: one part doing the actual work, and another exchangeable part that interfaces with the operating system and creates windows and buttons and menus and such stuff. This allows the software house to have different programmers for the different parts, maybe one programmer doing the actual mathematical algorithm ( or whatever ) and a different programmer handling windows and yet a different programmer handling OS X. It is quite possible that the OS X windows parts are written in Objective-C while the Microsoft Windows part might be written in C# and the algorithms written in C.

So, for now, if you are a starting programmer, stay in the terminal with C. If you want to program windows for OS X the best way is to move over to Objective C and Cocoa (the windows framework on OS X ). Objective is part very close to C and actually allows you to include "pure" C functions ( not the main program though ).

If you want to transfer over to Microsoft Windows, I would suggest you go for the not quite obvious solution of programming in Visual Basic. This is probably the fastest way to get things up and running in Windows.

Anyway, my five cents of thoughts, probably worth as much. Over to you ( or to other fellow forum thinkers ).
//Gunnar
 

Futhark

macrumors 65816
Original poster
Jun 12, 2011
1,237
175
Northern Ireland
Yes, and no. It sort of depends.

When you write "bare" C programs they rely on a library of standard functions. These functions include allowing you to write characters to the terminal using printf, getting characters from the terminal, connecting to an internet port and so on. These functions are more or less the same on the source code level on just about any operating system or computer today, thanks to standardisation. Incidentally the c-compiler more or less automatically includes these functions, but in c you still need to #include <stdio.h> or other functions. ( By the way, it is quite interesting to try to understand what happens in stdio.h, beware that it has some quite advanced concepts ) .

But the standard c libraries will not allow creating windows or getting events when you mouse click on a button or pinch with your fingers on an iPad, just two of many examples. These functions requires you to use other libraries. These libraries are very different on different operating systems: quite different on OSX compared to Windows 7 as one of many examples.

The difference between different operating systems when it comes to "windows" makes it quite difficult to write programs that work in several environments ( several Os-es ) . What the big guys does probably do is to divide the program into two parts: one part doing the actual work, and another exchangeable part that interfaces with the operating system and creates windows and buttons and menus and such stuff. This allows the software house to have different programmers for the different parts, maybe one programmer doing the actual mathematical algorithm ( or whatever ) and a different programmer handling windows and yet a different programmer handling OS X. It is quite possible that the OS X windows parts are written in Objective-C while the Microsoft Windows part might be written in C# and the algorithms written in C.

So, for now, if you are a starting programmer, stay in the terminal with C. If you want to program windows for OS X the best way is to move over to Objective C and Cocoa (the windows framework on OS X ). Objective is part very close to C and actually allows you to include "pure" C functions ( not the main program though ).

If you want to transfer over to Microsoft Windows, I would suggest you go for the not quite obvious solution of programming in Visual Basic. This is probably the fastest way to get things up and running in Windows.

Anyway, my five cents of thoughts, probably worth as much. Over to you ( or to other fellow forum thinkers ).
//Gunnar

Wow now that's what I call a reply !!!! Thank you so much for going into so much depth and explaining yourself so well. I'm only a few weeks into C and loving it. I will progress into Objective-C once I feel I have a reasonable understanding of C my first ever programming language. What I've learned so far is maths based so I have created several small apps which I look forward to developing even further as my knowledge of the language progresses.

For example I've created a loan repayment app that lets me input how much of a loan was taken out and then asks if there is interest on the loan and it calculates how much I will have to pay back. I then get to make payments and when I input a payment it deducts it from my loan total but when I close the program it's all lost hehehehehe I've not learned yet how to save information that can be continued again once the program is restarted? Is this easy to do? I know my book does explain this but it's quite near the end and I don't want to skip chapters
 

AdrianK

macrumors 68020
Feb 19, 2011
2,230
2
I've not learned yet how to save information that can be continued again once the program is restarted? Is this easy to do? I know my book does explain this but it's quite near the end and I don't want to skip chapters
You could write it to a text file to save, then read the contents when the program starts up. How you format that completely depends on what fields you need to store. Using a fixed length record would be an easy way to go.
 

Futhark

macrumors 65816
Original poster
Jun 12, 2011
1,237
175
Northern Ireland
You could write it to a text file to save, then read the contents when the program starts up. How you format that completely depends on what fields you need to store. Using a fixed length record would be an easy way to go.

I took a peak at the contents pages there and they mention saving to text file tutorials. Damn I want to skip chapters :D MUSTN'T SKIP CHAPTERS !!!
 

DrMotownMac

Contributor
Jul 11, 2008
383
207
Michigan
Interesting topic. I'm sort of a programming newbie too. When I was in college, 20+ years ago, I took a class in FORTRAN, and I learned a little BASIC and PASCAL back in high school. Anyway, I switched from engineering school to medicine, and that was the end of my programming. So, I've never programmed in C, C++, Java, Objective-C, or any more relevant languages, and I have no clue about object-oriented programming, Cocoa, XCode, etc.

So, per some suggestions I've read here and elsewhere, I just downloaded the iBook version of "Objective-C Programming: The Big Nerd Ranch Guide," and I just started reading it last week, along with working through the programs and challenges. Apparently, it walks you through several chapters of "essential C" before getting into Objective-C. Very interesting and quite a fun challenge!

Anyway, I'm curious which C book you're reading, and what you plan to do next. My goal is to become proficient enough to create my own app on the App Store...just to prove to myself that I'm an old dog who is still able to learn new tricks! Well, it's fun reading about others who are trying to learn this stuff too!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.