Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - return of incompatible reference does not trough an error on qcc: (2 Items)
   
return of incompatible reference does not trough an error on qcc  
Hi ,

The following sample program does not trough either compiler or linker error when compiled using qcc.

$ qcc test.cc

But, when I try to compile it with gcc it troughs the following error

test.cc: In function `int main()':
test.cc:11: error: invalid initialization of non-const reference of type 'unsign
ed int&' from a temporary of type 'unsigned int'
test.cc:3: error: in passing argument 1 of `void testa(unsigned int&)'

Somebody please tell me why the qcc is not detecting the incompatible reference type, ofcourse the output file fails to 
return the expected value at runtime.. 

void testa(unsigned int &x)
{
x=20;
}
main(void)
{
unsigned int a;
unsigned long b;
unsigned char ptr= 'a';
testa((unsigned int) b);
}

Thanks in Advance
Warm regards
Annam K


Re: return of incompatible reference does not trough an error on qcc  
Annam Krupakar wrote:
> Hi ,
> 
> The following sample program does not trough either compiler or linker error when compiled using qcc.
> 
> $ qcc test.cc
> 
> But, when I try to compile it with gcc it troughs the following error
> 
> test.cc: In function `int main()':
> test.cc:11: error: invalid initialization of non-const reference of type 'unsign
> ed int&' from a temporary of type 'unsigned int'
> test.cc:3: error: in passing argument 1 of `void testa(unsigned int&)'
> 
> Somebody please tell me why the qcc is not detecting the incompatible reference type, ofcourse the output file fails 
to return the expected value at runtime.. 

qcc is just a compiler driver. By default, when you invoke qcc t.cc it 
uses gcc 2.95, and you are comparing it to a newer version of gcc. 
Earlier versions of gcc (pre-gcc 3.4) were very permissive with respect 
to C++ and did not catch this error.

You can download gcc 4.2 from the core developments project on the 
foundry and then change the default compiler qcc uses.

Regards,

Ryan Mansfield