mewmew / uc

A compiler for the µC language.
57 stars 5 forks source link

semantics: Think carefully about how to handle tentative declaration #51

Closed mewmew closed 8 years ago

mewmew commented 8 years ago

Related to issue #50.

mewmew commented 8 years ago

Last tentative definition becomes the definition, unless defined explicitly (e.g. having an initializer).

Examples from GCC demonstrating this behaviour.

Contents of a.c:

int x;
int x;

char x;
u@x1 ~/Desktop> gcc -o a a.c
a.c:4:6: error: conflicting types for ‘x’
 char x;
      ^
a.c:2:5: note: previous declaration of ‘x’ was here
 int x;
     ^

Contents of a.c:

int x;
int x = 2;

char x;
u@x1 ~/Desktop> gcc -o a a.c
a.c:4:6: error: conflicting types for ‘x’
 char x;
      ^
a.c:2:5: note: previous definition of ‘x’ was here
 int x = 2;
     ^

Contents of a.c:

int x = 2;
int x;

char x;
u@x1 ~/Desktop> gcc -o a a.c
a.c:4:6: error: conflicting types for ‘x’
 char x;
      ^
a.c:1:5: note: previous definition of ‘x’ was here
 int x = 2;
     ^
mewmew commented 8 years ago

The scope handling of the semantic analysis takes tentative declarations into account. Should a specific issue arise in the future, then simply open a new issue with a bug label. Closing this issue for now.