title: Reserved keywords in Objective-C?
body: <p>At the CocoaHeads Öresund meeting yesterday, <a href="https://stackoverflow.com/users/165059/peylow">peylow</a> had constructed a great ObjC quiz. The competition was intense and three people were left with the same score when the final question was to be evaluated: How many reserved keywords does Objective-C add to C?</p>
  
  <p>Some spirited debate followed. All agreed that <code>@interface</code>, <code>@implementation</code> etc are all pre-processor directives rather than keywords, but how about something like <code>in</code>? It might be a keyword, but it's not a <em>reserved</em> keyword. For example, the following will compile without errors or warnings:</p>
  
  <pre><code>NSArray* in;
  for (in in in)
     NSLog(@"bwahahaa");
  </code></pre>
  
  <p>We concluded that ObjC adds <strong>no</strong> reserved keywords to C, and someone won a seemingly well-earned book.</p>
  
  <p>But today I tried some more systematic abuse on the compiler by trying things like this:</p>
  
  <pre><code>int self = 45;
  self++;
  int y = self;
  </code></pre>
  
  <p>That compiles fine, and the same code works replacing self for <code>BOOL, bycopy, inout, oneway, byref, SEL,</code> and <code>IMP</code>.</p>
  
  <p>Using <code>id</code> as the variable name, the first and last lines compile, but not the second one. The same goes for <code>Protocol</code>, and <code>Class</code>.</p>
  
  <p>Using <code>super</code>, the first line compiles, but not the second and third.</p>
  
  <p>With <code>YES</code>, <code>NO</code>, and <code>NULL</code>, all three lines fail to compile, probably because they are just defined as <code>true</code>, <code>false</code>, and <code>nil</code>.</p>
  
  <p>It looks to me like a lot of this is gcc getting confused and I'm not so sure it reflects what is and isn't a reserved keyword in Objective-C. Why, for example, is it ok to use <code>self</code> as the name of an int, but not <code>super</code>?</p>
  
  <p>The fact that the first assignment always works (except for with YES, NO, and NULL) would seem to support the idea that none of the candidates are technically reserved keywords that are not found in C. Or?</p>
  
  <p>Could someone please give us an authoritative explication of this thorny issue?</p>
  
  <p>Several people's honor is at stake.</p>
  
  <p>EDIT: As Nikolai Ruhe pointed out, we need a clear definition of "keyword" to proceed. Niko cited a Wikipedia article saying that a keyword is "a word or identifier that has a particular meaning".</p>
  
  <p>I think it is reasonable to use this definition from the same article:</p>
  
  <blockquote>
    <p>In many languages, such as C and
    similar environments like C++, a
    keyword is a reserved word which
    identifies a syntactic form. Words
    used in control flow constructs, such
    as if, then, and else are keywords. In
    these languages, keywords cannot also
    be used as the names of variables or
    functions.</p>
  </blockquote>
  
  <p>Furthermore, as the article states:</p>
  
  <blockquote>
    <p>Typically, when a programmer attempts
    to use a keyword for a variable or
    function name, a compilation error
    will be triggered.</p>
  </blockquote>
  
  <p>In this sense, then, are there any reserved keywords that are <a href="http://en.wikipedia.org/wiki/Reserved_word" rel="nofollow noreferrer">predefined in the language’s formal specifications and cannot be used as a user-defined name</a>?</p>