const array initialisation (bug?)
Pierangelo Masarati
masarati@aero.polimi.it
Wed Apr 12 05:38:00 GMT 2000
Hello.
This very simple program shows a different behaviour if compiled
with the gcc 2.91 coming with RedHat 6.2 (the expected one)
and with gcc 2.95.2 (the erroneous one?).
#include <iostream.h>
#include <math.h>
const double d1 = 1.;
const double dd1[2][1] = { { -d1 }, { d1 } };
const double d2 = (1.-sqrt(3.))/6.;
const double dd2[2][1] = { { -d2 }, { d2 } };
const double c = d2;
int main(void)
{
cout
<< "d1 = " << d1
<< ", dd1 = {" << dd1[0][0] << "," << dd1[1][0] << "}" << endl
<< "d2 = " << d2 << ", c = " << c
<< ", dd2 = {" << dd2[0][0] << "," << dd2[1][0] << "}" << endl;
return 0;
}
The expected behaviour, namely the constant array dd2 being correctly
initialised, has been obtained on different platforms. On the contrary,
gcc 2.95.2 does not initialise the array; this behaviour has been
obtained
both on a PC (RedHat Linux Box) and on a Digital Unix Alpha
(I can send the .ii and the log if required)
In case the expected behaviour is correct, this seems to be a bug; on
the
contrary, if this behaviour is erroneous, in my opinion the compiler
should at least warn that traditionally accepted behaviour is no longer
supported.
My regards, Pierangelo
Reading specs from
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp
-lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus
-trigraphs -D__STRICT_ANSI__ -D__ELF__ -D__unix__ -D__i386__ -D__linux__
-D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -ggdb -Wall -W
-pedantic -Acpu(i386) -Amachine(i386) -D__i386 -D__i386__ -D__i686
-D__i686__ -D__pentiumpro -D__pentiumpro__ const.cc const.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/include/g++
/usr/local/include
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../i686-pc-linux-gnu/include
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/include
/usr/include
End of search list.
The following default directories have been omitted from the search
path:
End of omitted list.
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cc1plus
const.ii -quiet -dumpbase const.cc -ggdb -Wall -W -pedantic -ansi
-version -o const.s
GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux-gnu) compiled
by GNU C version 2.95.2 19991024 (release).
as -V -Qy -o const.o const.s
GNU assembler version 2.9.5 (i386-redhat-linux) using BFD version
2.9.5.0.22
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/collect2 -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o const /usr/lib/crt1.o
/usr/lib/crti.o
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtbegin.o
-L/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2
-L/usr/local/gcc-2.95.2/lib const.o -lstdc++ -lm -lgcc -lc -lgcc
/usr/local/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtend.o
/usr/lib/crtn.o
--
Pierangelo Masarati, Ph.D. | voice: ++39(02)2399-8365
Dip. Ing. Aerospaziale | fax: ++39(02)2399-8334
Politecnico di Milano |
via La Masa 34, 20156 Italy | mailto:masarati@aero.polimi.it
http://www.aero.polimi.it/personale/vari/masarati.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: const.ii.bz2
Type: application/x-bzip2
Size: 6633 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20000412/829f5707/attachment.bz2>
More information about the Gcc-bugs
mailing list