How to initialize const in a struct in C (with malloc)

后端 未结 6 433
谎友^
谎友^ 2020-11-28 08:46

I have tried;

void *malloc(unsigned int);
struct deneme {
    const int a = 15;
    const int b = 16;
};

int main(int argc, const char *argv[])
{
    struct         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 09:35

    Interesting I found this C99 way is working in clang but not in gcc

    int main(int argc, const char *argv[])
    {
        struct deneme *pmydeneme = malloc(sizeof(struct deneme));
        *pmydeneme = (struct deneme) {15, 20};
        return 0;
    }
    

提交回复
热议问题