Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > obj-c and c/c++ ?

obj-c and c/c++ ?
Thread Tools
Fresh-Faced Recruit
Join Date: Feb 2002
Status: Offline
Reply With Quote
Mar 26, 2002, 04:55 PM
 
just a newbie question:
if i want to program on mac can i get along with Ansi c/c++ or do i need
obj-c ? (I won't learn it)

thanks

[ 03-26-2002: Message edited by: fafnir ]
     
Mac Enthusiast
Join Date: Dec 2000
Status: Offline
Reply With Quote
Mar 26, 2002, 05:00 PM
 
That depends on what apps you want to write. Simple apps which run in the Terminal can be written in C/C++, whilst Cocoa apps require Obj-C or Java.


My name's ...uh... it's a bummer man.
     
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Mar 26, 2002, 05:27 PM
 
or do i need
obj-c ? (I won't learn it)
It's a pretty clean C based OO language. Give it shot, you will not be let down. The language itself is very simple. Learning the frameworks on the other hand... takes some time but definitely fun!
iMac 17" G4 800MHZ & 768 SDRAM
     
Forum Regular
Join Date: Feb 2002
Location: Fort Lauderdale, Florida
Status: Offline
Reply With Quote
Mar 26, 2002, 05:38 PM
 
Originally posted by fafnir:
<STRONG>just a newbie question:
if i want to program on mac can i get along with Ansi c/c++ or do i need
obj-c ? (I won't learn it)

thanks

[ 03-26-2002: Message edited by: fafnir ]</STRONG>
Note that you can use mix and match c/c++ and objective-c in code. It's just the Cocoa ui stuff that is objective-c mandatory.
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 26, 2002, 06:07 PM
 
You can develop Cocoa applications in Obj-C or Java or AppleScript. Carbon apps can be built in C, C++, Pascal, or (REAL) Basic. You can create Pure Java apps on OS X as well, and Terminal-based apps in a great many languages.
Rick Roe
icons.cx | weblog
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Mar 26, 2002, 08:58 PM
 
In addition, there is Objective-C++, which allows you to use both Objective-C and C++ in the same source files. So basically, you could create a C++ Cocoa application. You would just be interacting with the UI using Objective-C method calls.


And one more thing... any programmer worth anything can pick up a new programming language in a matter of weeks (hours with a killer teacher). If you insist on not programming for a certain platform purely because it would involve learning a new language, then you couldn't be much of a programmer.

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
K++
Senior User
Join Date: Jan 2002
Location: NYC
Status: Offline
Reply With Quote
Mar 26, 2002, 09:15 PM
 
Originally posted by Detrius:
<STRONG>In addition, there is Objective-C++, which allows you to use both Objective-C and C++ in the same source files. So basically, you could create a C++ Cocoa application. You would just be interacting with the UI using Objective-C method calls.
</STRONG>
Explain this "Objective-C++", exactly where in Project Builder do you see it, and how does Project Builder now when to use C++ syntax and when to use Objective-C syntax. And more importantly where did you hear/read/make up such a thing?
     
Forum Regular
Join Date: Feb 2002
Location: Fort Lauderdale, Florida
Status: Offline
Reply With Quote
Mar 26, 2002, 11:40 PM
 
Originally posted by K++:
<STRONG>

Explain this "Objective-C++", exactly where in Project Builder do you see it, and how does Project Builder now when to use C++ syntax and when to use Objective-C syntax. And more importantly where did you hear/read/make up such a thing?</STRONG>
I just started with Cocoa myself, so correct me if i am wrong guys, but it seems you can make c/c++ function calls and instantiate c++ objects from right within your objective-c code. You dont have to change any project builder build flags.
     
Junior Member
Join Date: Feb 2002
Status: Offline
Reply With Quote
Mar 26, 2002, 11:55 PM
 
You need to name your files with the '.mm' extension to tell the compiler that it's an Objective-C++ source file. Since the Obj-C and C++ syntaxes don't conflict, there's no problem with the compiler telling which is which. For the full scoop, read this file on your hard drive, assuming you have a recent version of the developer tools installed:

/Developer/Documentation/ReleaseNotes/Objective-C++.html

Also, you're comparing Obj-C to C/C++... I would argue that Obj-C is closer to plain C than C++ is (it doesn't change how C code behaves like C++ sometimes does).

Given your seeming prejudice against Obj-C, you probably will find some excuse not to like it, but at least give it a try.

BTW when you're asking someone for help, it helps not to accuse them of making things up.

EDIT: Typo

[ 03-27-2002: Message edited by: Jeff Binder ]
self = [[JeffBinder alloc] init];
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Mar 27, 2002, 08:00 AM
 
Originally posted by mdcarter1:
<STRONG>

I just started with Cocoa myself, so correct me if i am wrong guys, but it seems you can make c/c++ function calls and instantiate c++ objects from right within your objective-c code. You dont have to change any project builder build flags.</STRONG>
There are limits to what you can do, as listed in Apple's description of Objective-C++. Specifically, you can't use C++ syntax on Objective-C objects (and vice-versa). You can, however, have C++ objects within an Objective-C class. However, it cannot be statically allocated. You will have to have a pointer and instantiate it within the init method.

If for some reason you don't have the documentation on your hard drive, you can this document here.

One more thing... the compiler relies rather heavily on that .mm extension. If you will be including a header somewhere down the chain that has Obj-C++, it would be a good idea to make your documents .mm files, even if that specific document doesn't actually have any Obj-C++ code in it. If it's referenced, even indirectly, this makes things a bit easier.

[ 03-27-2002: Message edited by: Detrius ]

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Mar 27, 2002, 08:08 AM
 
Originally posted by fafnir:
<STRONG>just a newbie question:
if i want to program on mac can i get along with Ansi c/c++ or do i need
obj-c ? (I won't learn it)

thanks

[ 03-26-2002: Message edited by: fafnir ]</STRONG>
I concur with the statements above, but as an honest question, may I ask what you have against Objective-C such that you won't learn it?
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
fafnir  (op)
Fresh-Faced Recruit
Join Date: Feb 2002
Status: Offline
Reply With Quote
Mar 27, 2002, 04:56 PM
 
Originally posted by Millennium:
<STRONG>
I concur with the statements above, but as an honest question, may I ask what you have against Objective-C such that you won't learn it?</STRONG>
First, thanks for the responses.

I have nothing against Obj-C, its only the fact that i will never (yes, i know, never say never and never say always...) have to code for macs. So call me lazy, but i like c++ and -more important- i dont want much trouble to re-use written Code or port a program.
Obj-c++ could be a workaround, although there are some Restrictions (you cant use Namespaces in obj-C++).
     
Junior Member
Join Date: Feb 2002
Status: Offline
Reply With Quote
Mar 27, 2002, 11:01 PM
 
If you will never have to code for Macs, than why did you ask the question in the first place?
self = [[JeffBinder alloc] init];
     
Dedicated MacNNer
Join Date: Mar 2001
Location: Iowa City, IA
Status: Offline
Reply With Quote
Mar 27, 2002, 11:48 PM
 
Originally posted by fafnir:
<STRONG>

First, thanks for the responses.

I have nothing against Obj-C, its only the fact that i will never (yes, i know, never say never and never say always...) have to code for macs. So call me lazy, but i like c++ and -more important- i dont want much trouble to re-use written Code or port a program. </STRONG>
Not a problem. Since, if you port a program, you have to rewrite the UI code anyway (unless you're doing Java/Swing or Tcl/Tk - and OS X has a very nice implementation of Tk, as it happens), you can port the ANSI C++ part of your codebase over easily and then paint a nice Aqua interface on it with Objective-C (or C++, if you want the extra work). The two languages can talk to each other.

By the way, although the Cocoa frameworks are peculiar to OS X, objective-c is available on every platform the GNU gcc compiler is available on, and that's a lot of platforms. There's also an effort called GNUStep to complete an open-source version of the OpenStep frameworks (Cocoa's predecessor).

[ 03-28-2002: Message edited by: Amorph ]
James

"I grew up. Then I got better." - Sea Wasp
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:25 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2