vv1133 vv1133 -3 years ago 64
C Question

Double parentheses of a function call?

Consider the following code:

#include <stdio.h>

int aaa(char *f, ...)
{
putchar(*f);
return 0;
}

int main(void)
{
aaa("abc");
aaa("%dabc", 3);
aaa(("abc"));
aaa(("%dabc", 3));
return 0;
}


I was wondering why the following lines:

aaa("abc");
aaa("%dabc", 3);
aaa(("abc"));


run without error, but the fourth line (seen below):

aaa(("%dabc", 3));


generates the following errors:


main.c:15:2: warning: passing argument 1 of 'aaa' makes pointer from integer without a cast

main.c:3:5: note: expected 'char *' but argument is of type `int'

Answer Source

The statement

aaa(("%dabc", 3));

calls the function aaa with the argument ("%dabc", 3) which returns the value 3.

Look up the comma operator for more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download