C++ ã³ã³ãã¤ã©ã«ãããå¤æ¸¡ãã®æé©å
ãããªããã£ãåã§ãªãã¨ãå°ããªæ§é ä½ (or å ±ç¨ä½) ãªãã¬ã¸ã¹ã¿æ¸¡ãã«ãªããã£ã¦ã®ã¯ C ã§æé©åãããã³ã¼ããæ¸ãéã«ããã°ãã°ä½¿ããããã¯ããã¯ãã§ã C++ ã ã¨ãã³ãã¼ã³ã³ã¹ãã©ã¯ã¿ããã¹ãã©ã¯ã¿ãããå ´åã¯ãã®æé©åãä¸å¯è½ãä»ã«ãè¨èªä»æ§çã«ç´°ããªæ¡ä»¶ã¯ããã®ããªãã¨ãããã³ã³ãã¤ã©ã®å®è£ ã§ãã®å¯å¦å¤æã¯ã©ããªã£ã¦ããã®ãã㨠SUN ã®ããã¥ã¡ã³ããèªãã§ããããã¨ã¦ãé å¼µã£ã¦ãã¦é©ããã
In compatibility mode (-compat[=4]), a class is passed indirectly if it has any one of the following:
- A user-defined constructor
- A virtual function
- A virtual base class
- A base that is passed indirectly
- A non-static data member that is passed indirectly
Otherwise, the class is passed directly.
In standard mode (the default mode), a class is passed indirectly if it has any one of the following:
- A user-defined copy constructor
- A user-defined destructor
- A base that is passed indirectly
- A non-static data member that is passed indirectly
Otherwise, the class is passed directly.
http://docs.sun.com/app/docs/doc/819-5267/6n7c46doi?l=ja&a=view#indexterm-311
ãããã¯ã¬ã¸ã¹ã¿æ¸¡ãå½ãª SPARC ã¢ã¼ããã¯ãã£åãã®ã³ã³ãã¤ã©ãä»®æ³é¢æ°ãããã®ã«ãã¹ãã©ã¯ã¿ããªããªãã¦ãã¨ã¯ãªããªãããå¾ãªããã©ãããããå ´åã®æé©åã¾ã§ãã¦ãã
ãã§ãGCC ã®å ´åã試ãã¦ã¿ã (gcc 4.0.1; i386) ãã©ããããªæãã ã£ãã
call __Z15createT_C_stylei movl %eax, 4(%esp) leal LC1-"L00000000002$pb"(%ebx), %esi movl %esi, (%esp) call L_printf$stub (snip) call __Z12createT_dtori subl $4, %esp movl -36(%ebp), %eax movl %eax, 4(%esp) movl %esi, (%esp) call L_printf$stub (snip) call __Z12createT_mfuni movl %eax, 4(%esp) movl %esi, (%esp) call L_printf$stub (snip) call __Z12createT_vfuni subl $4, %esp movl -32(%ebp), %eax movl %eax, 4(%esp) movl %esi, (%esp) call L_printf$stub
ããã¹ãã©ã¯ã¿ãä»®æ³é¢æ°ãããå ´åã¯ã常ã«åç §æ¸¡ãã«ãªãããããç¶æ¿ã¾ããã¯æªç¢ºèªã
ãã¡ãªã¿ã«ä½¿ç¨ããæ¤è¨¼ã³ã¼ãã¯ä»¥ä¸ã®ã¨ãããæé©åã«èå³ãããæ¹ã¯ãã©ãããå©ç¨ãã ããã
#include <stdio.h> struct T_C_style { int v; }; struct T_dtor { int v; ~T_dtor() {} }; struct T_mfun { int v; void foo(); }; struct T_vfun { int v; virtual void foo() {} }; #define CREATE(T) T create##T(int v) { T t; t.v = v; return t; } CREATE(T_C_style); CREATE(T_dtor); CREATE(T_mfun); CREATE(T_vfun); int main(int argc, char **argv) { int v = 0; sscanf(argv[1], "%d", &v); #define TEST(T) { T t(create##T(v)); printf("%d\n", t.v); } TEST(T_C_style); TEST(T_dtor); TEST(T_mfun); TEST(T_vfun); return 0; }
3æ21æ¥è¿½è¨:ãä¸ã®ã³ã¼ãã¯ãå®éã®é¢æ°å¼ã³åºãã«ãããæé©åææ³ã確èªããç®çã§æ¸ããã¦ãã¾ãããã®ãããã¤ã³ã©ã¤ã³å±éãããªããã (ãã³ãã¬ã¼ãã§ã¯ãªã) #define ãç¨ãã¦é¢æ°ãå®ç¾©ãã¦ãã¾ãã