Linux用gcc编译通过运行不了,c - C代码可在Windows(使用Visual Studio编译)上运行,但不能在Linux(使用gcc)上编译 - 堆栈内存溢出...

您的代码与您发布的代码完全一样,并通过我的gcc生成了这些消息

6398652.c:4:5: error: function declaration isn’t a prototype [-Werror=strict-prototypes]

6398652.c: In function ‘main’:

6398652.c:4:5: error: old-style function definition [-Werror=old-style-definition]

6398652.c:18:3: error: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int *’ [-Werror=format]

6398652.c: In function ‘create_array’:

6398652.c:25:3: error: implicit declaration of function ‘malloc’ [-Werror=implicit-function-declaration]

6398652.c:25:21: error: incompatible implicit declaration of built-in function ‘malloc’ [-Werror]

cc1: all warnings being treated as errors

此更改的版本可以干净地编译

#include

#include

int *create_array(int n, int initial_value);

int main(void) {

int *arr;

int num;

int numOfNum;

printf("Store this integer:\n");

scanf("%d", &num);

printf("Store the integer this amount of time:\n");

scanf("%d", &numOfNum);

arr = create_array(num, 1);

if (arr == NULL) {

printf("ERROR\n");

} else {

printf("Array stored in this location: %p\n", (void*)arr);

}

return 0;

}

int *create_array(int n, int initial_value) {

int *pointer;

int i;

pointer = malloc(10 * sizeof *pointer);

for (i = 0; i < n; i++) {

int *p;

p = pointer;

p += n*(sizeof *p);

*p = initial_value;

}

return pointer;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值