C followed by a comma separator

I read some error materials to avoid when writing C programs, and I came across the following code:

#include <stdio.h>

void foo(int param)
{
  printf("foo is called\n");
  printf("%d\n",param);
}

int main()
{
  return foo,(1);
}

The code above does not contain errors and warnings (it only shows a warning when -Wall is activated), but when I run a small program, nothing is displayed. The foo function is not called due to the comma delimiter.

My question is: why does the C standard allow such syntax? Should the compiler give an error in this case? In what context can this syntax be used in some real case?

Thanks in advance,

PD: I am using GCC 4.8.3

EDIT:

( , -Wall)

+4
4

C - , , , .

C , C - , .

C Unix

"UNIX , , ". - (https://en.wikiquote.org/wiki/Unix)

, , .

++ .

,, : https://en.wikipedia.org/wiki/Comma_operator

. , . , , . , , , SFINAE (http://en.cppreference.com/w/cpp/language/sfinae). , , , .

+5
return foo,(1);

:

foo; // Nothing happens. This does not call the function.
return (1);

, :

foo(1);
return 1;
+5

foo,(1); foo , (1) .

, , for.

int i, j;
for (i = 0, j = 1; i < 10; i++, j *= 2) {
    printf("%d %d\n", i, j);
}
+4

, , , , , comma operator.

, , .

, , . , foo , 1.

. ? , , , , -Wall ( -Wextra). .

, . ( - )

#include <stdio.h>

void foo(int param)
{
    printf("foo is called\n");
    printf("%d\n",param);
}

int main()
{
    //return foo,(1);
    return foo(0),1;
}

$ ./bin/commafoo
foo is called
0

$ echo $?
1

, , , , - .

+2
source

Source: https://habr.com/ru/post/1609657/


All Articles