0

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?

Spikatrix
  • 20,225
  • 7
  • 37
  • 83
  • Did you try looking at its [source code](http://cdecl.org/files/cdecl-blocks-2.5.tar.gz) to see how it interprets such identifiers? – Remy Lebeau Mar 25 '15 at 14:20
  • @RemyLebeau , The source code is too large. It's very difficult to read and understand it. – Spikatrix Mar 26 '15 at 07:37

1 Answers1

1

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    `"returning"` is allowed if you are entering English text to translate into code, eg: `function returning int` translates to `int f()`. So it makes sense for `"pointer"` and `"array"` to be reserved since they are used in English text as well. But `"ptr"`? Oh wait, I just tried `declare foo as array 5 of ptr to int` and it translated to `int *foo[5]`, so I guess cdecl treats `"ptr"` as an alias for `"pointer"`. – Remy Lebeau Mar 27 '15 at 02:48
  • That makes sense. Please add that into your answer. – Spikatrix Mar 27 '15 at 02:52