C++ reference return/parameter value
来源:互联网 发布:人工智能软件 编辑:程序博客网 时间:2024/06/16 09:37
- 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]
}
- C++ reference return/parameter value
- Parameter passing in Java - by reference or by value?
- Value copy & reference copy (C#)
- Differenct between return by value and by reference
- 解决Deprecated: Assigning the return value of new by reference
- [C#] C# Concepts: Value vs Reference Types
- 返回值与输出参数比较(return value or out parameter)
- php5.3 的问题 “Assigning the return value of new by reference is deprecated in xxxx”
- Assigning the return value of new by reference is deprecated in xxxx
- php报错:Deprecated: Assigning the return value of new by reference is deprecated in
- PHP显示Deprecated: Assigning the return value of new by reference is deprecated in解决办法
- PHP显示Deprecated: Assigning the return value of new by reference is deprecated in解决办法
- PHP显示Deprecated: Assigning the return value of new by reference is deprecated in解决办法
- 关于Assigning the return value of new by reference is deprecated的错误提示
- Deprecated: Assigning the return value of new by reference is deprecated in……【解决方法】
- Deprecated: Assigning the return value of new by reference is deprecated in……解决方法
- Value-typed Field of a Reference-typed Argument (C#)
- 关于MyEclipse较检异常 Invalid result location value/parameter 及Cannot return from outside a function or
- C Standard Library
- 用REALbasic语言写网页程序!
- 前台显示表字段
- 使用CFileDialog 同时选择多个文件或文件夹
- DuMing is My name!
- C++ reference return/parameter value
- 屏幕录制方法
- Windows的内存结构
- 赞一下EMS
- IT同仁们,能让日常生活更健康的几个小细节,你做到了几个?
- Tomcat5.5配置虚拟路径
- javascript操作多选列表框
- Java Web层框架比较—— 比较JSF、Spring MVC、Stripes、Struts 2、Tapestry和Wicket
- solaris memory leak