将结构成员转换为结构指针

时间:2019-07-09 03:39:46

标签: c++

假设我有如下代码。我不知道scm的值将是

scm = (struct sc *)scsr.sd;

我认为在完成此分配后,scm的值将与scsr.sd的地址相同,但是它们是不同的。谁能告诉我这段代码要做什么?是否将scm的大小设置为与scsr.sd相同?

#define SOME_CONST 10240

struct sc{
    char *pd;
};

struct scsr{
    double  dummy;
    char *sd;
};

int main()
{
    char sb[SOME_CONST + sizeof(struct sc)];
    struct sc *scm;
    struct scsr sr;
    sr.sd= sb;
    scm = (struct sc *)sr.sd;
    return 0;
}

0 个答案:

没有答案