wshini7316 发表于 2012-10-8 12:19:45

结构体中的成员**p怎么分配空间?

typedef struct{
    char   **p32;
}LCM_STR;

lcm_str = (LCM_STR *)malloc(sizeof(LCM_STR));
lcm_str->p32 = (char **)malloc(50);
lcm_str->*p32 = (char *)malloc(50);


\main.cpp(322) : error C2065: 'p32' : undeclared identifier
\main.cpp(322) : error C2297: '->*' : illegal, right operand has type 'int'

jathenal 发表于 2012-10-8 13:11:02

lcm_str->*p32的写法不行,试试*lcm_str->p32
另外指针本身只需要4字节就够,malloc(50)没必要吧

laber_1912 发表于 2012-10-8 13:23:31

大多数情况下,sizeof(LCM_STR) =1 word = 32Bit

jackiezeng 发表于 2012-10-8 13:25:31

4字节吧 ,
指针4字节 , 指向指针的指针 也是4字节。

Etual 发表于 2012-10-8 13:58:06

还不如用指针数组
        char* p32;

        p32 = (char*) malloc(50);
        p32 = (char*) malloc(50);
        strcpy(p32, "Hello");
        strcpy(p32, "world");

wshini7316 发表于 2012-10-9 12:31:42

jathenal 发表于 2012-10-8 13:11 static/image/common/back.gif
lcm_str->*p32的写法不行,试试*lcm_str->p32
另外指针本身只需要4字节就够,malloc(50)没必要吧 ...

*lcm_str->p32
可以用 谢谢!
页: [1]
查看完整版本: 结构体中的成员**p怎么分配空间?