Search code examples
cidentifiervariable-namescdecl

What are the variable names that are disallowed in cdecl other than the ones that cannot be used in any program?


I've been playing around with cdecl and I've noticed that some names are not allowed as identifiers in it although GCC compiles them perfectly.

For example, if I write

int ptr;

or

int pointer;

or

int array;

cdecl gives a "syntax error" but when I use it in a program, GCC compiles them without any problems. So, there are some identifiers that are not permitted in cdecl.

Which are the identifiers that cannot be used in cdecl, but can be used in a program(i.e, the program compiles)? Why aren't they permitted?


Solution

  • pointer and array are in cdecl's list of reserved keywords:

    char *keywords[] = {
      "function",
      "returning",
      "array",     // <--
      "pointer",   // <--
      "reference",
      "member",
      "const",
      "volatile",
      "noalias",
      "struct",
      "union",
      "enum",
      "class",
      "extern",
      "static",
      "auto",
      "register",
      "short",
      "long",
      "signed",
      "unsigned",
      "char",
      "float",
      "double",
      "void",
      NULL
    };
    

    As for ptr, I don't know why cdecl thinks that is invalid. Entering the following expression into cdecl also fails:

    declare ptr as int

    But this works:

    declare ptr1 as int

    So clearly it does not like ptr, either.