握艹,C你main啊!
嵌入式Linux
共 5665字,需浏览 12分钟
·
2024-06-25 08:23
[ ] (warning
The following C++ dynamic initialization routines will probably not get called:
___sti___12_cpp_main_cpp_mm from cpp_main.o
main() (from c_main.o) was probably not compiled as C++.
typedef struct
{
unsigned int id;
unsigned char len;
} Msg;
class Test {
public:
Test() { }
int n;
static int st_n;
static Msg st_m;
};
Msg mm={0xaa,0x55};
Msg Test::st_m = mm;
int Test::st_n = 0x123;
.data febd0000+000008 _mm
.text 00000b9e+000002 _multiBreak
.text 00000b9a+000000 _multiCall
.text 00001b2c+00004a _open
.text 000018b6+000084 _raise
.text 00001b06+000026 _read
.text 00001856+000060 _signal
.bss febd006c+000008 _st_m__4Test
.data febd0008+000004 _st_n__4Test
-
C的main,性格直爽,心里不藏任何秘密;
-
C++的main,内敛且有内涵,还悄悄地帮你做静态成员初始化。
// c_main.c
extern int test_func(void);
#ifndef CPP_MAIN
int main(void)
{
test_func();
return 0;
}
#endif
// cpp_main.cpp
typedef struct
{
unsigned int id;
unsigned char len;
} Msg;
class Test {
public:
Test() { }
int n;
static int st_n;
static Msg st_m;
};
Msg mm={0xaa,0x55};
Msg Test::st_m = mm;
int Test::st_n = 0x123;
Test gt;
extern "C" {
int test_func(void)
{
Test t;
int x;
t.n = 12;
if(t.st_n == 0x123)
{
x = 100;
}
if(t.st_m.id == 0xaa)
{
x = 200;
}
if(gt.st_m.id == 0xaa)
{
x = 2200;
}
return x;
}
}
int main()
{
test_func();
return 0;
}
评论