3 ms·
Already the first example is wrong. So I stopped reading. % cc -std=c11 -o dingens dingens.c dingens.c:6:9: error: redefinition of 'i' int i = 10;
by fdik 12y ago
Already the first example is wrong. So I stopped reading.
% cc -std=c11 -o dingens dingens.c
dingens.c:6:9: error: redefinition of 'i'
int i = 10;
^
dingens.c:5:9: note: previous definition is here
int i;
^
1 error generated.
% cat dingens.c
#include <stdio.h>
int main()
{
int i;
int i = 10;
printf("hello, world\n");
return 0;
}
%
- anant 12y agoHe clearly mentions that the statements are not in a function body, rather just in the global portion of a C file.
- azinman2 12y agoThat's because you put it inside a function versus inside the file outside of a function. It'll compile then, even on clang with -std=c11. I just tried it now and it worked. From his webpage: "Reminding you that it’s a separate source file and not a part of the function body or compound statement"