03-08-2012 02:09 PM
I believe that there may be a problem in the compiler syntax checker.
I accidentally typed this for a function call and the complier did not flag an error.
It compiled cleanly, but reported an incorrect value.
Here is the goof. Notice the comma between the function name and the left parenthesis.
It seems that the complier should complain about this as it is not correct syntax.
03-09-2012 02:14 PM
Thank you for bringing this to our attention. I agree that the compiler should be presenting and error in this case, and I will make our R&D colleagues aware of this issue.
03-09-2012 02:28 PM
Although non-sensical, that's actually a legal expression. It's perfectly legal to have a C statement consisting of a single identifier, or a single expression. For example:
Note also that GetCtrlVal is also an expression in C. It's a function pointer that can be assigned to a function pointer variable, for example. Therefore, this is also legal:
In C, you can add as many commas between statements as you like. It imposes an order of evaluation of the comma-separated items. See here for more information. Therefore, this is also valid:
Finally, you can always add parentheses around any operands, which is why this is also valid:
03-12-2012 10:29 AM
I've noticed that the compiler will throw a warning (Missing argument list for call to function) if you do this:
However, it is silent if you do this:
Any reason for this or is this just something that was overlooked?
03-12-2012 03:57 PM
That warning is probably a legacy of when the C syntax was considered a significant departure from Pascal that it could conceivably trip up programmers unaccustomed to the C syntax. (Pascal allows zero-argument functions to be called without an argument list).
This warning is only displayed for simple, single-identifier expressions, which is the only situation in which you might conceivably mean intend to call the function while inadvertently leaving out the argument list. But when you add a comma to the expression, you no longer have a simple expression. Instead you have a sequence of two expressions: the function identifier and something else.
You also don't get the warning if your statement is myFunc = GetCtrlVal; since your intention in this case is to use the function name as a constant expression, not as a function call.