What is the relationship between #line and the global static scope?
Given a C file (foo.c) like this:
#line 1 "a.c"
static int bar = 1;
#line 2 "b.c"
static int bar = 2;
#line 2 "a.c"
int foo(){
return bar;
}
Are the two bar declarations in the same area or separate areas (e.g. foo () returns 1)?
Note. I am interested in correct behavior based on the standard, not just "what my compiler does" (hence the "Language Advocate" tag).
source to share
The information #line
does not change the translation unit (TU). Your TU (source file plus included files) contains two definitions of the same variable ( static
). This is mistake. The compiler rejects it. As it reports the error, directives can be affected #line
, but the error will be reported regardless of directives #line
- the compiler tries to compile one TU and the TU is faulty.
source to share