大宇私人领地伊甸园丨宁愿做了后悔,也不要错过后悔[www.mrdayu.com]
注册

24小时联系邮箱:[email protected]

所有文章
大宇私人伊甸园: 首页 > 所有文章 > 编程人生 > C/C++语言 > initialization makes integer from pointer without a cast [enabled by default]


友情链接:


initialization makes integer from pointer without a cast [enabled by default]

发布时间:2018/11/22 C/C++语言 阅读:37

遇到情况:

[[email protected] STDC]$ gcc stdc_realloc.c 
stdc_realloc.c: In function ‘main’:
stdc_realloc.c:4:9: warning: initialization makes integer from pointer without a cast [enabled by default]
  char p=(char *)malloc(10);
         ^
stdc_realloc.c:6:4: warning: assignment makes integer from pointer without a cast [enabled by default]
   p="helloworld";

解决方法:

①通过翻译我是看不懂有哪些问题。

②只能通过源码来看问题所在。

源码()错误的:

#include <stdlib.h>
#include <stdio.h>
int main(){
        char p=(char *)malloc(10);
        if(p){
                p="helloworld";
                        printf("SIZE=%d\t%s\n",sizeof(p),p);
        }
        return 0;
}

更正后:

#include <stdlib.h>
#include <stdio.h>
int main(){
        char *p=(char *)malloc(10);
        if(p){
                p="helloworld";
                        printf("SIZE=%d\t%s\n",sizeof(p),p);
        }
        return 0;
}
char *p=(char *)malloc(10);
The bottom line, for me, is simple.

Let’s hope it doesn’t take 500 years for a discipline of testing to becomes the standard for software developers.

From:dayu

您好!请登录

合作网站快捷登录:
点击取消回复

已有0评论

    大宇博客

    点击这里给我发消息 点击这里给我发消息 点击这里给我发消息 点击这里给我发消息