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

Rezet

macrumors 6502a
Original poster
Hey my frind was wondering how C++ works on mac. He is a PC programmer and always thought thet one cannot use C++ on macs. I don't program anything like that so i really can't give specific answers. could anyone post some keypoint on how C++ works on macs? Like what programs one need to get where to get em? Is it same as on PC? etc...
 

FattyMembrane

macrumors 6502a
Apr 14, 2002
966
154
bat country
pretty much every language available works on the mac os. project builder (the free development tools included with osx) allows you to code in c++. most windows users have absolutely no idea what you can or can't do with a mac; if they did, they wouldn't be windows users any more :D .

but yeah, c++ works like it would on any other system. you can compile it from the command-line like on unix systems, or in project builder / codewarrior.

P.S. things like the finder, quicktime, and itunes (any carbon app for that matter) are written in c++
 

MisterMe

macrumors G4
Jul 17, 2002
10,709
69
USA
Originally posted by FattyMembrane
pretty much every language available works on the mac os. project builder (the free development tools included with osx) allows you to code in c++. most windows users have absolutely no idea what you can or can't do with a mac; if they did, they wouldn't be windows users any more :D .

but yeah, c++ works like it would on any other system. you can compile it from the command-line like on unix systems, or in project builder / codewarrior.

P.S. things like the finder, quicktime, and itunes (any carbon app for that matter) are written in c++
To amplify your point, through System 6.0.8, the Mac operating system was written in Pascal-assisted 68000 assembly language. However, C++ has been the language of choice for Mac programming for more than a decade. Except for the legacy portions of the OS, System 7.0 through MacOS 9.2.2 were written in C++. IIRC, C++ remains the language of Carbon.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
osx is unix. just about every language under the sun (no pun intended) can be developed on unix. tell your friend that.

many people, myself included, feel that unix is by far the best development platform.
 

crenz

macrumors 6502a
Jul 3, 2003
619
27
Shanghai, China
Re: C++ and macs...

Originally posted by Rezet
He is a PC programmer and always thought thet one cannot use C++ on macs.

There's two issues here: language and development environment.

As a programmer, he should be aware that all programming languages are in general platform-ignorant; they can be used anywhere. (A special case is e.g. Visual Basic; while Basic can be used anywhere, Visual Basic has been heavily modified by Microsoft towards use on Windows. But even for VB, there's a compatible product available on Mac: RealBasic).

However, the key thing is the development environment. On Windows, Microsoft has created a fantastic IDE for C++ ("integrated development environment"), Visual C++ . It helps programmers to be much more productive by organizing their work. I'm not aware of any software on Linux that has the same functionality (notice that IDEs have not been invented by MS, though; e.g. Borland has been producing them for years (and in a great way!) as well). Visual C++ and associated products are rather expensive, unless you are a student.

For Mac OS X, Apple ships the Project Builder for free, with every copy of Mac OS X. I am convinced that the influx of tools for OS X is mostly due to the PB. It provides an easy and intuitive way to code apps on the Mac. Yes, it's different from MSVC and takes a bit getting used to, but it has lots of functionality. And I'm convinced it's as productive as MSVC.

And the best thing is: Things are going to be even better in Panther with Xcode. An article recently linked on MacBytes.com touted Xcode as something like the "better C++" and praised Apple for making things so much easier for programmers. I'm really curious to check out that one...

As an addendum, let me say that Mac OS X also lets you develop in Objective C, AppleScript (allows for GUI apps as well!), Perl, Python, PHP out of the box. As in: Everything is included with the copy of X.2 you bought.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
IDEs exist on many platforms for many different languages. using the MS offering as the standard against which to measure others is about as useful as holding Pascal as the standard programming language.

i first noticed IDEs popping up in the mid 80s. the first i used was Lightspeed Pascal and Lightspeed C on the mac, around 1986 iirc.
 

crenz

macrumors 6502a
Jul 3, 2003
619
27
Shanghai, China
Originally posted by zimv20
using the MS offering as the standard against which to measure others is about as useful as holding Pascal as the standard programming language.

Well, I'd say it is about as useful as using C++ as the standard for complex application development. There is a difference between using something as a standard for comparison and declaring something "the" standard.

Imagine the Project Builder would only support Pascal. Obviously, you'd want to compare Project Builder/Pascal against e.g. KDevelop/gcc, MSVC, Interface Builder/Qt and wxWindows (oops, runs on Mac also :)) to see whether development on the Mac platform is as full-featured as it is on Linux and Windows. If it were deficient, it wouldn't give you the option to use MSVC instead (since you want to use a Mac), but it would give you an excuse to kick Apple's behind.

I think MSVC6 is an excellent IDE, even though it is geared towards C++ (which I use, but hate) and Windows (which I only use to develop software for clients). For many (a majority of GUI application developers?), it is the IDE, since Windows/C++ is their only market.

That's why I use MSVC here to illustrate that Apple plays (almost) in the same league. I couldn't use e.g. Delphi, because (unfortunately) not so many people care about Delphi/Kylix anymore...
 

crenz

macrumors 6502a
Jul 3, 2003
619
27
Shanghai, China
wxWindows

Just remembered something. Point your friend to http://www.wxwindows.org/ . wxWindows is a free, open-source toolkit that lets you develop GUI apps for Linux, Windows, OS 9 and OS X. For many apps, you can even just recompile the code to port it to another platform. I'm a huge fan of it, since (even if you don't need the cross-platformness) it makes Windows programming so much more easy and logical (MFC is not so much fun to use... :( ).
 

Fender2112

macrumors 65816
Aug 11, 2002
1,135
386
Charlotte, NC
a bit off topic...

What does iirc mean? I've seen it quite a bit in tha past several weeks. I though it was a typo for IRC but I don't think all these folks are making the same mistake. :)
 

MisterMe

macrumors G4
Jul 17, 2002
10,709
69
USA
Re: a bit off topic...

Originally posted by Fender2112
What does iirc mean? I've seen it quite a bit in tha past several weeks. I though it was a typo for IRC but I don't think all these folks are making the same mistake. :)
IIRC, IIRC means If I Remember Correctly.
 

synthetickittie

macrumors regular
Dec 17, 2002
223
0
Boston
anyone have a clue why when I used project builder to do my homework, intoduction to computer science(c++ coding), it will not compile things I write.

The steps I take are as follows:

1) open project builder and click file-> new project.

2) from the menu that pops up I choose "c++ tool" from under the "tool" header

3) name the project any random name

4)In the source folder on the left side I click on "main.cpp"

5) on the right side I code:

#include <iostream>

int main ()
{
std::cout << "Test\n";
return 0;
}

6) file->save

7)build-> build and run

After that tells me the build failed with 79 errors. Im new to coding, well at least c++ Ive only done web based coding before, and my teaches by what we use in our lab section(first one is tomorrow) which are unix shells and I know I could do the same within the terminal but the way we have to compile them in the lab it with a compiler on that computer which I do not have access of.
 

bousozoku

Moderator emeritus
Jun 25, 2002
15,728
1,899
Lard
Originally posted by synthetickittie
anyone have a clue why when I used project builder to do my homework, intoduction to computer science(c++ coding), it will not compile things I write.

The steps I take are as follows:

1) open project builder and click file-> new project.

2) from the menu that pops up I choose "c++ tool" from under the "tool" header

3) name the project any random name

4)In the source folder on the left side I click on "main.cpp"

5) on the right side I code:

#include <iostream>

int main ()
{
std::cout << "Test\n";
return 0;
}

6) file->save

7)build-> build and run

After that tells me the build failed with 79 errors. Im new to coding, well at least c++ Ive only done web based coding before, and my teaches by what we use in our lab section(first one is tomorrow) which are unix shells and I know I could do the same within the terminal but the way we have to compile them in the lab it with a compiler on that computer which I do not have access of.

I just created the project, pasted your code, and it compiled and ran fine. Perhaps, it's something else? You might post some of the errors.

cubist:

Of course, you can use Carbon within C or C++ but the bindings are strictly C.

zimv20:

I believe that Borland are credited with the first IDE in Turbo Pascal 3.0 in 1985. The LightSpeed IDEs were slicker though.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
Re: Re: a bit off topic...

Originally posted by MisterMe
IIRC, IIRC means If I Remember Correctly.

ah, ambiguity strikes again. i always thought it was "if i recall correctly"

both work, obviously
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
Originally posted by synthetickittie


#include <iostream>

int main ()
{
std::cout << "Test\n";
return 0;
}

i haven't coded c++ since '98, really, but i'd try:

Code:
#include <iostream.h>

int main (int argc, char** argv) 
{
    cout << "Test" << endl;
    return 0;
}
 

bousozoku

Moderator emeritus
Jun 25, 2002
15,728
1,899
Lard
Originally posted by zimv20
i haven't coded c++ since '98, really, but i'd try:

Code:
#include <iostream.h>

int main (int argc, char** argv) 
{
    cout << "Test" << endl;
    return 0;
}

That's fine with compilers prior to the standard, but the header files have changed names since then.
 

Santiago

macrumors 6502
Jun 14, 2002
314
312
Mountain View, California
The correct name for all built-in C++ headers is a single lowercase word, without a ".h" at the end. For built-in C headers, they can be included via their original names, or via their original names with the ".h" chopped off and a "c" added in front. (e.g. "<cstdlib>" or "<stdlib.h>")

Note that string and string.h/cstring are completely different files. string contains C++ string objects. string.h/cstring contains C functions.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
Originally posted by Santiago
The correct name for all built-in C++ headers is a single lowercase word, without a ".h" at the end. For built-in C headers, they can be included via their original names, or via their original names with the ".h" chopped off and a "c" added in front. (e.g. "<cstdlib>" or "<stdlib.h>")

thanks for the info
 

jettredmont

macrumors 68030
Jul 25, 2002
2,731
328
Originally posted by synthetickittie
anyone have a clue why when I used project builder to do my homework, intoduction to computer science(c++ coding), it will not compile things I write.

The steps I take are as follows:

1) open project builder and click file-> new project.

2) from the menu that pops up I choose "c++ tool" from under the "tool" header

3) name the project any random name

4)In the source folder on the left side I click on "main.cpp"

5) on the right side I code:

#include <iostream>

int main ()
{
std::cout << "Test\n";
return 0;
}

Most likely one of thos 76 errors came from the linker and said something like "could not find main". "main" needs to have two arguments in c/c++; anything else just won't work:

int mainc ( int argc, char* argv[] );

(argv can be char** too, maybe even char * const argv[] or somesuch ... but it's gotta be there!)

In general, you just need to look at the first 1-2 errors you get, fix those, and try compiling again. Oftentimes, one error in code will cause many errors in the compiler.

OTOH, 76 seems like a lot of errors. Not sure if this error would cause that many.
 

jettredmont

macrumors 68030
Jul 25, 2002
2,731
328
Originally posted by zimv20
i haven't coded c++ since '98, really, but i'd try:

Code:
#include <iostream.h>

int main (int argc, char** argv) 
{
    cout << "Test" << endl;
    return 0;
}

This would work, except you need to preface "cout" and "endl" with "std::" or (more likely) put "using namespace std;" after the include line at the top.
 

jettredmont

macrumors 68030
Jul 25, 2002
2,731
328
Re: C++ and macs...

Originally posted by Rezet
Hey my frind was wondering how C++ works on mac. He is a PC programmer and always thought thet one cannot use C++ on macs. I don't program anything like that so i really can't give specific answers. could anyone post some keypoint on how C++ works on macs? Like what programs one need to get where to get em? Is it same as on PC? etc...

C++ works great on the Mac, whether you prefer a full-featured IDE (Project Builder) or a command line (emacs/vi + gcc).

You will NOT find MFC on the Mac (as though you wanted to ...) You will instead find Cocoa.

Also, while interface programming in MSVC is done entirely in straight C (or pidgin C++ with MFC), interface programming on the Mac is generally done in Objective C or Java (there is a C++ Cocoa wrapper I believe, but no one uses it because it makes more sense to use Obj-C/C++ for the UI).

With the inclusion of ObjC++ in gcc3 last year, it is very easy to use a C++ cross-platform code base with a Cocoa/ObjC++ front end (prior to ObjC++ you would have had to make your core application a library with a C API, then link your ObjC front end to it ... doable but kludgy).

Personally, I find Project Builder to be a vastly superior coding environment to MSVC++. Heck, for one thing, the performance-optimizing tools (Sampler, etc) are about 100x easier to use than Microsoft's "Easy 15-step, Recursive, CLI-only and you figure out how to interpret the entrails PROFILE procedure".

The only killer on the Mac currently is that gcc (the compiler ProjectBuilder uses) is incredibly slow to build compared to MSVC's cc, and the output is highly less optimized than the Windows output. On a G4/733 my compile times are 30-45 minutes; on a P4 1.5GHz the same compile (with a Windows front end intstead of a Cocoa front end of course, but otherwise the same code) takes 5-7 minutes. A dual 1.42GHz Mac still takes 15 minutes, which brings it into the reasonable realm, but still a lot slower than the PC. That's the only thing that keeps my primary development machine as a PC today.

I only have XCode's initial Jaguar release (I can't spare a machine for Panther betas so I haven't gotten an updated XCode), and, aside from performance problems (100% CPU while sitting idle for a day ... not doing a rendezvous bulid for anyone else either ...) it is a huge advance. Before I gave up on it, I was using it to get my half-hour builds done faster than the seven minutes it takes on my Windows box, which was a first.

So, I'd recommend your friend try Panther (when it comes out) or Jaguar (today) for C++ development. I suspect he wouldn't at all be disappointed by the development experience that will come shipped with a new G5 after Panther ships.
 

bousozoku

Moderator emeritus
Jun 25, 2002
15,728
1,899
Lard
Originally posted by jettredmont
Most likely one of thos 76 errors came from the linker and said something like "could not find main". "main" needs to have two arguments in c/c++; anything else just won't work:

int mainc ( int argc, char* argv[] );

(argv can be char** too, maybe even char * const argv[] or somesuch ... but it's gotta be there!)

In general, you just need to look at the first 1-2 errors you get, fix those, and try compiling again. Oftentimes, one error in code will cause many errors in the compiler.

OTOH, 76 seems like a lot of errors. Not sure if this error would cause that many.

That's fine except that I pasted his source code into a new project and I got zero complaints and it rain perfectly.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
Originally posted by jettredmont
This would work, except you need to preface "cout" and "endl" with "std::" or (more likely) put "using namespace std;" after the include line at the top.

ahhhh, yes. the namespace stuff was just being hammered out when all my projects went java.

C++ old skool, yo. ;-)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.