Quoting from here,
In C, there are two different namespaces of types: a namespace of struct/union/enum tag names and a namespace of typedef names.
name.c
$ cat name.c
#include<stdio.h>
typedef long long long2;
int long2 () {
return 4;
}
int main() {
printf("hello, world!");
return 0;
}
$ gcc name.c -o name
name.c:4: error: 'long2' redeclared as different kind of symbol
name.c:3: error: previous declaration of 'long2' was here
$
name2.c
$ cat name2.c
#include<stdio.h>
int four() {
return 4;
}
struct dummy {
int member;
};
int main() {
struct dummy four;
}
$ gcc name2.c -o name2
$
I am trying to understand C namespace conflicts.
-
In the first case, why is there a conflict? Do functions also belong to the typedef namespace?
-
In the second case, why is there no conflict at all? The function and the variable both are named four. Why does the compiler allow that? How is
&foursupposed to be resolved?
C has four different name spaces for identifiers:
gototype).See also C99 6.2.3.
So your two question can be answered as: