I am not sure if there is a bug declaration for g++ 3.X (have not checked the doc yet). On the other hand, g++ 4.X, however, could compile the example code below silently. Anyway, seems for g++ 3.X, reference operator ‘&’ and address operator ‘&’ would confuse the compiler when they are used the same time in one expression. There is also a workaround there to bypass the complain from older compiler.
/home/daveti/Ctest: cat reference.cpp
#include <stdio.h>
typedef struct _A
{
int a;
int b;
}A;
int main( void)
{
A x;
A &y = x;
if ( &(y.a) || 1)
{
printf("Sounds goodn");
}
return 0;
}
/home/daveti/Ctest: g++ -o reference reference.cpp
reference.cpp: In function `int main()’:
reference.cpp:14: invalid operands of types `A&’ and `int’ to binary `
operator!=’
/home/daveti/Ctest: g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –enable-shared –enable-threads=posix –disable-checking –with-system-zlib –enable-__cxa_atexit –host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
/home/daveti/Ctest: cat reference2.cpp
#include <stdio.h>
typedef struct _A
{
int a;
int b;
}A;
int main( void)
{
A x;
A &y = x;
int p = y.a;
if ( &(p) || 1)
{
printf("Sounds goodn");
}
return 0;
}
/home/daveti/Ctest: g++ -o reference2 reference2.cpp
/home/daveti/Ctest: ./reference2
Sounds good
/home/daveti/Ctest: g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –enable-shared –enable-threads=posix –disable-checking –with-system-zlib –enable-__cxa_atexit –host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
I have noticed you don’t monetize your website, don’t waste your traffic, you can earn additional cash every month
because you’ve got high quality content. If you want to know how to make extra
$$$, search for: Mertiso’s tips best adsense
alternative