C中的“const”和错误“只读位置的分配”

时间:2016-08-18 07:12:44

标签: c pointers

我正在用C编写一个链接列表,这是我的代码

const

我在data后添加struct strlist S = { "Hello World" }; printf("%s", S.data++); printf("%s", S.data) 以避免任何人修改数据指针,如下所示:

int Append(struct strlist *S, char *a) {
    struct strlist next = { a };
    S->next = malloc(sizeof(struct strlist));
    *S->next = next;
    return 0; 
}

然后我用这个函数添加新元素

assignment of read-only location

In Clang它可以编译,也可以工作。 但在gcc中我收到错误char * const str 为什么?有更好的方法吗?

next这意味着我可以更改字符串而不是指针,不是吗?

为什么我无法将struct复制到@Html.ActionLink("display name", "action", "Contorller" new { id = 1 },Html Attribute=new {Attribute1="value"})

0 个答案:

没有答案