#include<stdio.h>
void jigar (int ji)
{
printf("%d",ji);
}
void main()
{
int a=32;
(jigar)(a);
}
When I run this program with the -Wall option, the compiler doesn’t give any warning or error, it works fine. But when I compile this program in MIPS cross-compiler tool chain, then it gives an error:
(jigar)(a);
at this line. Now my question is: why gcc for linux doesn’t point out my silly mistake?
There’s nothing wrong with
(jigar)(a);as it is acceptable in standard C. The reason your MIPS compiler gives warning is because perhaps that compiler does not fully implement standard C.Edit: Regarding Als’s request for why this is standard C, here’s how:
Look at the ISO C grammar here: http://www.cs.dartmouth.edu/~mckeeman/cs48/mxcom/doc/notation/c.html and note that a function call
can have
postfix-expressionas function. There is a rule that says:where
primary-expressioncould be anidentifier, that is function name. However there is also this rule:and if you follow the chain of rules from
expressionyou get back atprimary-expressionagain. Therefore indirectly, you have:The semantics of C indicates that
( expression )has the same type and value asexpression(1). According to the grammar, (jigar)(a) is correct. Semantically,(jigar)andjigarhave the same type and value. Therefore C accepts(jigar)(a)and the functionality is the same asjigar(a).Edit 2:
(1) C99 draft section 6.5.1 article 5:
P.S. anyone knows where I can get the documentation for ISO C, like a list of features or something? I have seen people quote it, but I couldn’t find it myself.