views:

497

answers:

6

How is objective-c possibly a superset of C? It makes no sense. There is no stack in objective-c from what I can tell. Also, in C there is no need to use [] whenever invoking a method. Please explain.

+12  A: 

There is a stack in Objective-C, just objects aren't (for the most part) found on it. C types are, though, so in that sense C + (objects on the heap) is a superset of C. Similarly, there are no methods in C, so [object message] has no meaning in C. Adding it, as Objective-C does, still means that C exists in its entirety so C + (object messaging syntax) is a superset of C.

Compare that with the notion that C++ doesn't allow implicit pointer conversion from void *, so C - (implicit pointer conversion) is less than C, so C++ cannot possibly be a superset.

Graham Lee
How can it be a superset if objects are not used on the stack? You can put a struct on the stack in objective-c.
Greg
Because objects are used at all, which means it has a feature that C doesn't; and it has all of the C features ;-)
Graham Lee
I wish I could do +2 lol
Jason Coco
A: 

Hi Greg, Objective-C does use the same call stack as C. And the brackets are part of the "superset" which means they are part of the Objective-C syntax but not part of the "subset" C syntax.

Adam Alexander
+1  A: 

I highly suggest an Obj-C book. Objective-C adds Smalltalk-style messaging. These are done in the form of...

[someObject someMethod:param1];

That's what the brackets are for. You aren't directly calling the method, you are sending a message to the object. You aren't guaranteed the object will even respond to the message. That's why there is a different style syntax.

And there is a stack in Objective-C.

Jab
A: 

Just learn: The Objective-C 2.0 Programming Language.

mouviciel
A: 

The fact that it's a superset means that that valid C code is also valid Objective-C code.

What works in C that you think doesn't in Objective-C ?

Jaka Jančar
Putting variables on the stack.
Greg
You can put variables on the stack in Objective-C. What are you talking about?
Jason Coco
+3  A: 

All C code is valid in an Objective-C program. Objective-C's syntax is part of the superset.