If Objective C is a strict superset of C, then why doesn't it compile?

Consider the following source file, which is (at least should be) valid C.

void id() {
}

      

I am trying to compile it with gcc -c test.m

, but I am getting the following error:

test.m:1: error: ‘id’ redeclared as different kind of symbol
<built-in>:0: error: previous declaration of ‘id’ was here 

      

If Obj-C was a strict superset, does that mean that all valid C programs are also valid Obj-C programs? Please note that I have #import

nothing, no links.

Of course, maybe LLVM (1) is doing something magical by default, or maybe it's a bug.

(1): i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (based on Apple Inc. build 5658) (LLVM build 2336.1.00)

EDIT . Let me clarify this question - the question is not in part id

, I know it has a special meaning. I can say that it is usually said that Obj-C is a strict superset of C. However, this cannot be so if it has keywords that contradict valid C programs.

So either id is not reserved by the compiler, or Obj-C is not a strict superset. The question of this question is to ask what is the matter, or is there something obvious that I am missing.

+3


source to share


2 answers


Superset means it adds some extra functionality. For example, id

in this case. This is a specific type in Objective C. And these additional superset functions always replace the subset.

Its just habitual that people use the term strict superset. You need to take it with a pinch of salt!

See these old posts on SO for a similar discussion



Is Object C 2.0 the correct superset of C?

Which dialect of C is Objective-C a "strong superset" of?

+5


source


id

is the keyword for "any type of object" in ObjectiveC. In C, this would probably be the same as writing



void int() {
}

      

0


source







All Articles