Y
Yogesh
Hi all,
Please look at the code below:
int main (int argc, char * const argv[])
{
int * i = (int *)malloc(sizeof(int));
*i = 50;
int &badref = *i;
printf("%d\n",badref);
delete i;
printf("%d\n",badref);
//This reference is bad coz "i" is deleted
badref = 70;
printf("%d\n",badref);
return 0 ;
}
I compiled and ran this program on gcc 4.0 and it worked.
it prints:
50
50
70
In the above case I would call the reference "badref" a bad reference
because
it is alias to var that is deleted.
My question is:
Do we check if the reference is bad, before using it?
If so, how?
Regards,
Yogesh Kini
Please look at the code below:
int main (int argc, char * const argv[])
{
int * i = (int *)malloc(sizeof(int));
*i = 50;
int &badref = *i;
printf("%d\n",badref);
delete i;
printf("%d\n",badref);
//This reference is bad coz "i" is deleted
badref = 70;
printf("%d\n",badref);
return 0 ;
}
I compiled and ran this program on gcc 4.0 and it worked.
it prints:
50
50
70
In the above case I would call the reference "badref" a bad reference
because
it is alias to var that is deleted.
My question is:
Do we check if the reference is bad, before using it?
If so, how?
Regards,
Yogesh Kini