This is also somewhat compiler dependant as some compilers store references in symbol table while others do so using stack.This one runs on stack fundamentals.This is against C++ standards but this is just a trick for this code on big endian which stores reference on stacks.This won't work for little endian.
On Tue, Jul 12, 2011 at 5:50 PM, Ashish kumar Jain <[email protected]>wrote: > Dev C++ > > > On Tue, Jul 12, 2011 at 5:48 PM, Anand Saha <[email protected]> wrote: > >> Which compiler? http://www.ideone.com/7nnse >> >> -- >> >> >> On Tue, Jul 12, 2011 at 5:42 PM, Ashish kumar Jain < >> [email protected]> wrote: >> >>> You think so! Time to think again. :) >>> >>> >>> >>> #include<iostream> >>> >>> using namespace std; >>> >>> >>> >>> int main(void) >>> >>> { >>> >>> int a=10 ,b=4; >>> >>> int& c=a; >>> >>> >>> >>> cout<<"\n-"<<a; >>> >>> a+=20; >>> >>> cout<<"\n-"<<c; >>> >>> /********************/ >>> >>> //Addyour code here. >>> >>> >>> >>> *(unsigned long*)(((unsigned long)&b)-((unsigned long)&a-( >>> unsigned long)&b)) = (unsigned long)&b; >>> >>> >>> >>> /*********************/ >>> >>> >>> >>> >>> >>> cout<<"\n-"<<c; >>> >>> c=999; >>> >>> cout<<"\n-"<<b; >>> >>> >>> >>> >>> >>> cin.get(); >>> >>> return 0; >>> >>> } >>> >>> >>> >>> >>> On Tue, Jul 12, 2011 at 1:06 PM, Anand Saha <[email protected]> wrote: >>> >>>> Yep, and http://www.parashift.com/c++-faq-lite/references.html#faq-8.5 >>>> >>>> -- >>>> >>>> >>>> On Tue, Jul 12, 2011 at 12:50 PM, sunny agrawal < >>>> [email protected]> wrote: >>>> >>>>> Once a reference is initialized to an object, it cannot be changed to >>>>> refer to another object. >>>>> Ref. Bruce Eckel - ch11 >>>>> >>>>> So its Not possible >>>>> -- >>>>> Sunny Aggrawal >>>>> B-Tech IV year,CSI >>>>> Indian Institute Of Technology,Roorkee >>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>> >>> >>> >>> -- >>> Regards, >>> Ashish >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Regards, > Ashish > > -- Regards, Ashish -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
