C++ reference return/parameter value
2008-03-25 11:36
148 查看
souce C++ codes.
Point getPoint1(Point &p)
{
Point *pp = new Point(p);
return *pp;
}
Point &getPoint2(Point &p)
{
Point *pp = new Point(p);
return *pp;
}
Point getPoint3(Point p)
{
Point *pp = new Point(p);
return *pp;
}
Point &getPoint4(Point p)
{
Point *pp = new Point(p);
return *pp;
}
int main(int argc, char *argv[])
{
Point p0;
Point p1 = getPoint1(p0);
Point p2 = getPoint2(p0);
Point p3 = getPoint1(p0);
Point p4 = getPoint2(p0);
}
2. instructions analysis codes. (Sun C++ 5.6 Patch 117549-02 2005/02/08, SPARC)
Point getPoint1(Point &p)
{
st %i0,[%fp+68] # point the space to store return value, which is allocaded by caller
st %i1,[%fp+72] # point to p object
Point *pp = new Point(p);
call __1c2n6FI_pv_ # call constructor function of Point()
mov 28,%o0 # %o0 should be the address of pp which is return above
mov %o0,%i5
ld [%fp+72],%l0 # load the beginning of p object address
or %g0,28,%g1 # g0 always is 0, and 28 is the size of class Point
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2 # load value from p
bg 1b
st %l2,[%o0+%g1] # store value (loaded from p) to pp, it's a loop operations
st %i5,[%fp-4]
return *pp;
ld [%fp+68],%l1 # load the address of return Point object
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%i5+%g1],%l2 # %i5 is the beginning address of new created object pp
bg 1b
st %l2,[%l1+%g1] # store value of pp to return address
jmp %i7+8
restore
}
Point &getPoint2(Point &p)
{
st %i0,[%fp+68] # point to parameter p
Point *pp = new Point(p);
call __1c2n6FI_pv_
mov 28,%o0 # it should be %o0 = %o0 + 28
mov %o0,%i5
ld [%fp+68],%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2
bg 1b
st %l2,[%o0+%g1] # copy parameter p to local pp
st %i5,[%fp-8]
return *pp;
ba .L9
mov %i5,%i4
mov %i4,%i0 # %i4 = %i5 = %o0 = address of local pp
jmp %i7+8
restore
}
Point getPoint3(Point p)
{ st %i0,[%fp+68] # return value object, it will be copied to really return value
st %i1,[%fp+72] # p object
Point *pp = new Point(p);
call __1c2n6FI_pv_
mov 28,%o0
mov %o0,%i5
ld [%fp+72],%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2
bg 1b
st %l2,[%o0+%g1] # copy value from parameter p to local pp
st %i5,[%fp-4]
return *pp;
ld [%fp+68],%l1
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%i5+%g1],%l2
bg 1b
st %l2,[%l1+%g1] # copy value from local pp to temporary return space allocated by caller
jmp %i7+8
restore
}
Point &getPoint4(Point p)
{ st %i0,[%fp+68]
Point *pp = new Point(p);
call __1c2n6FI_pv_
mov 28,%o0
mov %o0,%i5
ld [%fp+68],%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2
bg 1b
st %l2,[%o0+%g1]
st %i5,[%fp-8]
return *pp;
ba .L15
mov %i5,%i4
mov %i4,%i0
jmp %i7+8
restore
}
int main(int argc, char *argv[])
{
st %i0,[%fp+68]
st %i1,[%fp+72]
Point p0;
Point p1 = getPoint1(p0);
add %fp,-60,%o0 # frame of getPoint1
add %fp,-32,%l1 # 60 - 32 = 28, it's the size of class Pointer; which is used in getPoint(...)
# that is to say, we first allocated space
call __1cJgetPoint16FrnFPoint__0_
mov %l1,%o1 # %l1 is the address of new allocated object;
Point p2 = getPoint2(p0); # Point &getPoint2(Point &p)
call __1cJgetPoint26FrnFPoint__1_
mov %l1,%o0
add %fp,-88,%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%o0+%g1],%l2
bg 1b
st %l2,[%l0+%g1] # copy the temporary variable to destination address
# there is an assign operation, Point p1 = Point &p2;
Point p3 = getPoint1(p0);
add %fp,-116,%o0
call __1cJgetPoint16FrnFPoint__0_
mov %l1,%o1
Point p4 = getPoint2(p0);
call __1cJgetPoint26FrnFPoint__1_
mov %l1,%o0
add %fp,-144,%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%o0+%g1],%l2
bg 1b
st %l2,[%l0+%g1]
}
Point getPoint1(Point &p)
{
Point *pp = new Point(p);
return *pp;
}
Point &getPoint2(Point &p)
{
Point *pp = new Point(p);
return *pp;
}
Point getPoint3(Point p)
{
Point *pp = new Point(p);
return *pp;
}
Point &getPoint4(Point p)
{
Point *pp = new Point(p);
return *pp;
}
int main(int argc, char *argv[])
{
Point p0;
Point p1 = getPoint1(p0);
Point p2 = getPoint2(p0);
Point p3 = getPoint1(p0);
Point p4 = getPoint2(p0);
}
2. instructions analysis codes. (Sun C++ 5.6 Patch 117549-02 2005/02/08, SPARC)
Point getPoint1(Point &p)
{
st %i0,[%fp+68] # point the space to store return value, which is allocaded by caller
st %i1,[%fp+72] # point to p object
Point *pp = new Point(p);
call __1c2n6FI_pv_ # call constructor function of Point()
mov 28,%o0 # %o0 should be the address of pp which is return above
mov %o0,%i5
ld [%fp+72],%l0 # load the beginning of p object address
or %g0,28,%g1 # g0 always is 0, and 28 is the size of class Point
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2 # load value from p
bg 1b
st %l2,[%o0+%g1] # store value (loaded from p) to pp, it's a loop operations
st %i5,[%fp-4]
return *pp;
ld [%fp+68],%l1 # load the address of return Point object
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%i5+%g1],%l2 # %i5 is the beginning address of new created object pp
bg 1b
st %l2,[%l1+%g1] # store value of pp to return address
jmp %i7+8
restore
}
Point &getPoint2(Point &p)
{
st %i0,[%fp+68] # point to parameter p
Point *pp = new Point(p);
call __1c2n6FI_pv_
mov 28,%o0 # it should be %o0 = %o0 + 28
mov %o0,%i5
ld [%fp+68],%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2
bg 1b
st %l2,[%o0+%g1] # copy parameter p to local pp
st %i5,[%fp-8]
return *pp;
ba .L9
mov %i5,%i4
mov %i4,%i0 # %i4 = %i5 = %o0 = address of local pp
jmp %i7+8
restore
}
Point getPoint3(Point p)
{ st %i0,[%fp+68] # return value object, it will be copied to really return value
st %i1,[%fp+72] # p object
Point *pp = new Point(p);
call __1c2n6FI_pv_
mov 28,%o0
mov %o0,%i5
ld [%fp+72],%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2
bg 1b
st %l2,[%o0+%g1] # copy value from parameter p to local pp
st %i5,[%fp-4]
return *pp;
ld [%fp+68],%l1
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%i5+%g1],%l2
bg 1b
st %l2,[%l1+%g1] # copy value from local pp to temporary return space allocated by caller
jmp %i7+8
restore
}
Point &getPoint4(Point p)
{ st %i0,[%fp+68]
Point *pp = new Point(p);
call __1c2n6FI_pv_
mov 28,%o0
mov %o0,%i5
ld [%fp+68],%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%l0+%g1],%l2
bg 1b
st %l2,[%o0+%g1]
st %i5,[%fp-8]
return *pp;
ba .L15
mov %i5,%i4
mov %i4,%i0
jmp %i7+8
restore
}
int main(int argc, char *argv[])
{
st %i0,[%fp+68]
st %i1,[%fp+72]
Point p0;
Point p1 = getPoint1(p0);
add %fp,-60,%o0 # frame of getPoint1
add %fp,-32,%l1 # 60 - 32 = 28, it's the size of class Pointer; which is used in getPoint(...)
# that is to say, we first allocated space
call __1cJgetPoint16FrnFPoint__0_
mov %l1,%o1 # %l1 is the address of new allocated object;
Point p2 = getPoint2(p0); # Point &getPoint2(Point &p)
call __1cJgetPoint26FrnFPoint__1_
mov %l1,%o0
add %fp,-88,%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%o0+%g1],%l2
bg 1b
st %l2,[%l0+%g1] # copy the temporary variable to destination address
# there is an assign operation, Point p1 = Point &p2;
Point p3 = getPoint1(p0);
add %fp,-116,%o0
call __1cJgetPoint16FrnFPoint__0_
mov %l1,%o1
Point p4 = getPoint2(p0);
call __1cJgetPoint26FrnFPoint__1_
mov %l1,%o0
add %fp,-144,%l0
or %g0,28,%g1
1:
subcc %g1,4,%g1
ld [%o0+%g1],%l2
bg 1b
st %l2,[%l0+%g1]
}
相关文章推荐
- 出现 Assigning the return value of new by reference is deprecated in xxxx &&“Warning: Call-time pass-by-reference has been deprecated”怎么办?
- ECShop后台站点地图关于 Deprecated: Assigning the return value of new by reference is deprecated的错误的解决办法
- 【C++】reference parameter-引用参数
- [C++] right value reference
- 《Inside C++ Object 》 阅读笔记(1), NRV(Named Return Value)
- c++ reference value
- 返回值与输出参数比较(return value or out parameter)
- store procudure's output parameter & return value
- C++ Error : initial value of reference to non-const must be an lvalue
- 显示Deprecated: Assigning the return value of new by reference is deprecated in解决办法
- Deprecated: Assigning the return value of new by reference is deprecated in……【解决方法】
- Google C++ Coding Style:右值引用(Rvalue Reference)
- 解决Deprecated: Assigning the return value of new by reference
- Effective C++ Item 10,11 Have assignment operators return a reference to *this Handle assignment to self in operator =
- PHP 解决版本问题:"Assigning the return value of new by reference is deprecated"
- ecshopv2.7.3 商品批量上传中出错:Assigning the return value of new by reference is deprecated in
- Differenct between return by value and by reference
- C++之宁以pass-by-reference-to-const替换pass-by-value(20)---《Effecitive C++》
- zencart 显示Deprecated: Assigning the return value of new by reference is deprecated
- What does “warning: not all control paths return a value” mean? (C++)