C++?е????????????????
???????????? ???????[ 2015/8/18 13:37:43 ] ??????????????????? ???????
????3????????const
??????????????????const???????????const?????????????????в????????????????????
???????????VS????????
???????????????????????????????????????const???????????????????
???????????????????????????????????????????漲?????????????????漲???
?????????????”const int* pointer=&a”???????????*pointer????????????*pointer?????????в?????
?????????????????????????????????????????????const????????????????????????????????????????????????????????????????
?????????VS???ó???
???????????????????????const???????????????????????????????????????????????????????????????????????????????????????????const??
?????????????”int* const pointer=&b”???????????pointer????????????????????в??????????????????????????*pointer????????
?????????????VS???????ó???
?????????????????????????????????????????????????????????????????????????????????????”const int* const pointer=&c”???????????pointer??*pointer???????????????????????????в?????
??????????????ν??”???????ó???”??????????潲?????????????????ó?????C++???????????const???ú?const?????????á??????????????????????????????????????????????????????const??????????????ù????const??????????????????const??????????У?Const double const& a=1?????const double& a=1??
??????????????????????????const????????????????????????????——?????????????????????????*???????const??????????????????????????????????const??????????????????????????????????????????????????????????
????4??????????????
??????????????????μ???????????????????????:
????#include<iostream>
????using namespace std;
????int main(int argc?? char** argv)
????{
????int i=1;
????int& ref=i;
????int x=ref;
????cout<<"x is "<<x<<endl;
????ref=2;
????int* p=&i;
????cout<<"ref = "<<ref<<"?? i = "<<i<<endl;
????}
??????????????g++ test.c?????????????objdump -d a.out?????main????????λ????????£?
????08048714 <main>:
????8048714: 55????????push %ebp
????8048715: 89 e5??????mov %esp??%ebp
????8048717: 83 e4 f0 and $0xfffffff0??%esp//?main?????????argc??argv????λ??
????804871a: 56 push %esi
????804871b: 53 push %ebx
????804871c: 83 ec 28 sub $0x28??%esp
????804871f: c7 44 24 1c 01 00 00 movl $0x1??0x1c(%esp) //??0x1?浽esp??????У???int i=1
????8048726: 00
????8048727: 8d 44 24 1c lea 0x1c(%esp)??%eax// esp???????????i????????eax
????804872b: 89 44 24 18 mov %eax??0x18(%esp)//???????eax?е??????i????????????????е????ref????int& ref=i
????804872f: 8b 44 24 18 mov 0x18(%esp)??%eax//???????esp?е?ref????eax????i????
????8048733: 8b 00 mov (%eax)??%eax//??????eax?е????????????????eax 8048735: 89 44 24 14 mov %eax??0x14(%esp) //???????eax?е???????????esp?е?x????x=ref
????8048739: c7 44 24 04 00 89 04 movl $0x8048900??0x4(%esp)
????8048740: 08
????8048741: c7 04 24 40 a0 04 08 movl $0x804a040??(%esp)
????8048748: e8 cb fe ff ff call 8048618 <_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@plt>
????804874d: 8b 54 24 14 mov 0x14(%esp)??%edx
????8048751: 89 54 24 04 mov %edx??0x4(%esp)
????8048755: 89 04 24 mov %eax??(%esp)
????8048758: e8 5b fe ff ff call 80485b8 <_ZNSolsEi@plt>
????804875d: c7 44 24 04 38 86 04 movl $0x8048638??0x4(%esp)
????8048764: 08
????8048765: 89 04 24 mov %eax??(%esp)
????8048768: e8 bb fe ff ff call 8048628 <_ZNSolsEPFRSoS_E@plt>//??8048739~8048768??Щ???????"cout<<"x is "<<x<<endl;"
????804876d: 8b 44 24 18 mov 0x18(%esp)??%eax//???????esp?е?ref????eax??
????8048771: c7 00 02 00 00 00 movl $0x2??(%eax) //??0x2?浽eax???????
????8048777: 8d 44 24 1c lea 0x1c(%esp)??%eax// esp???????????i????????eax
????804877b: 89 44 24 10 mov %eax??0x10(%esp) //???????eax?е????????i???????????????esp?е?p
????804877f: 8b 5c 24 1c mov 0x1c(%esp)??%ebx
????8048783: 8b 44 24 18 mov 0x18(%esp)??%eax
????8048787: 8b 30 mov (%eax)??%esi
????8048789: c7 44 24 04 06 89 04 movl $0x8048906??0x4(%esp)
????8048790: 08
????8048791: c7 04 24 40 a0 04 08 movl $0x804a040??(%esp)
????8048798: e8 7b fe ff ff call 8048618 <_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@plt>
????804879d: 89 74 24 04 mov %esi??0x4(%esp)
????80487a1: 89 04 24 mov %eax??(%esp)
????80487a4: e8 0f fe ff ff call 80485b8 <_ZNSolsEi@plt>
????80487a9: c7 44 24 04 0d 89 04 movl $0x804890d??0x4(%esp)
????80487b0: 08
????80487b1: 89 04 24 mov %eax??(%esp)
????80487b4: e8 5f fe ff ff call 8048618 <_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@plt>
????80487b9: 89 5c 24 04 mov %ebx??0x4(%esp)
????80487bd: 89 04 24 mov %eax??(%esp)
????80487c0: e8 f3 fd ff ff call 80485b8 <_ZNSolsEi@plt>
????80487c5: c7 44 24 04 38 86 04 movl $0x8048638??0x4(%esp)
????80487cc: 08
????80487cd: 89 04 24 mov %eax??(%esp)
????80487d0: e8 53 fe ff ff call 8048628 <_ZNSolsEPFRSoS_E@plt>//??Щ???????"cout<<"ref = "<<ref<<"?? i = "<<i<<endl;"
????80487d5: b8 00 00 00 00 mov $0x0??%eax
????80487da: 83 c4 28 add $0x28??%esp
????80487dd: 5b pop %ebx
????80487de: 5e pop %esi
????80487df: 89 ec mov %ebp??%esp
????80487e1: 5d pop %ebp
????80487e2: c3 ret
??????????????????????????????????????е????????????
????????int& ref=i;
????8048727: 8d 44 24 1c lea 0x1c(%esp)??%eax// esp???????????i????????eax
????804872b: 89 44 24 18 mov %eax??0×18(%esp)//???????eax?е??????i????????????????е????ref????int& ref=i
???????int* p=&i;
????8048777: 8d 44 24 1c lea 0x1c(%esp)??%eax// esp???????????i????????eax
????804877b: 89 44 24 10 mov %eax??0×10(%esp) //???????eax?е????????i???????????????esp?е?p
???????????????????????е?????????????????????????????????????????????????”??????????????????????????”??????????????????????????????????????????????
????5???????????????
????????????????????????????????????????????????????????????????????????????????δ????????????????????????C++????????????????????????????????
???????????????????????????????????????????????????????????У????????????????????????????????????????????????п?????????????????????????????????ε??????????????ε????????????????????????????????????????κβ????????????????????У????????????????????α????????
???????????????У?????????????????????????????????п??????????????????????????????????????????α????????????????????βε??κβ?????????????????????????д??????????????????е???α?????????????????????????β??????κβ???????????????????е???α?????
???????????????????????????????????????????????????????????????????κζ??????ò?????????????????????????????????????????е???????????????????????????????????????е???????????????????????????????????????????????????????????????????е???????????????????????????????????á?
?????ο?????
????[1]The C++ Programming Language(Special Edition)??Bjarne Stroustrup
????[2] ANSI C++ Standard
????[3] ???????
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11