In crafty 23.2
line 540 of data.c is: int time_limit = 100;
line 570 of data.c is: int time_limit;
Why does this compile without error?
crafty bug?
Moderators: hgm, Rebel, chrisw
-
- Posts: 900
- Joined: Tue Apr 27, 2010 3:48 pm
Re: crafty bug?
Maybe the C standard allows it?
I was as surprised as you at first, but I just tried to compile this, and it works fine:
However if the second definition of t contains an initialization, it fails (even if it's initialized to 100 again).
I tried with gcc, but I suppose crafty 23.2 has been compiled correctly by many compilers, which is why I suspect it's allowed by the standard.
I was as surprised as you at first, but I just tried to compile this, and it works fine:
Code: Select all
#include <stdio.h>
int t=100;
int t;
int main (void)
{
printf ("%d\n", t);
return t;
}
I tried with gcc, but I suppose crafty 23.2 has been compiled correctly by many compilers, which is why I suspect it's allowed by the standard.
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: crafty bug?
It is ok, although it was not intended and the second declaration has been removed...rbarreira wrote:Maybe the C standard allows it?
I was as surprised as you at first, but I just tried to compile this, and it works fine:
However if the second definition of t contains an initialization, it fails (even if it's initialized to 100 again).Code: Select all
#include <stdio.h> int t=100; int t; int main (void) { printf ("%d\n", t); return t; }
I tried with gcc, but I suppose crafty 23.2 has been compiled correctly by many compilers, which is why I suspect it's allowed by the standard.
Re: crafty bug?
Hi,Maybe the C standard allows it?
I am not a geek, but try your code with these GCC flags and see what happens.
-ansi -pedantic -Wall -Wextra -Werror
-
- Posts: 900
- Joined: Tue Apr 27, 2010 3:48 pm
Re: crafty bug?
Just tried it... gcc still doesn't have any complaints about the code.Look wrote:Hi,Maybe the C standard allows it?
I am not a geek, but try your code with these GCC flags and see what happens.
-ansi -pedantic -Wall -Wextra -Werror
Re: crafty bug?
Compiler: Default compilerrbarreira wrote:Just tried it... gcc still doesn't have any complaints about the code.Look wrote:Hi,Maybe the C standard allows it?
I am not a geek, but try your code with these GCC flags and see what happens.
-ansi -pedantic -Wall -Wextra -Werror
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make clean
rm -f wtest.o warning_test.exe
g++.exe -c wtest.c -o wtest.o -I"C:/Dev-Cpp/include" -I"C:/MingW/include" -I"C:/Dev-Cpp/pthreads-w32-2-8-0-release" -ansi -pedantic -Wall -Wextra -Werror
wtest.c:5:5: error: redefinition of 'int t'
wtest.c:3:5: error: 'int t' previously defined here
make.exe: *** [wtest.o] Error 1
Execution terminated
-
- Posts: 900
- Joined: Tue Apr 27, 2010 3:48 pm
Re: crafty bug?
It also fails if I use g++ (with or without the strict options), but not with gcc.
Probably one more difference between C and C++.
Probably one more difference between C and C++.
Re: crafty bug?
Yes, gcc.exe does not even give a warning. In fact C++ is supposed to cove C too, but apparently experts say there are subtle differences, like IIRC defining structures inside functions,... . But IMO it makes sense to write C code such that it would be compiled with both GCC and G++. That is, the C subset of C++.rbarreira wrote:Just tried it... gcc still doesn't have any complaints about the code.Look wrote:Hi,Maybe the C standard allows it?
I am not a geek, but try your code with these GCC flags and see what happens.
-ansi -pedantic -Wall -Wextra -Werror
-
- Posts: 900
- Joined: Tue Apr 27, 2010 3:48 pm
Re: crafty bug?
Wikipedia has a list with quite a few small incompatibilities, but it doesn't cover the case in this thread:Look wrote: Yes, gcc.exe does not even give a warning. In fact C++ is supposed to cove C too, but apparently experts say there are subtle differences, like IIRC defining structures inside functions,... . But IMO it makes sense to write C code such that it would be compiled with both GCC and G++. That is, the C subset of C++.
http://en.wikipedia.org/wiki/Compatibil ... nd_C%2B%2B