malloc()和隐式转换 [英] malloc() and implicit cast

查看:93
本文介绍了malloc()和隐式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了常见问题解答: http://c-faq.com /malloc/mallocnocast.html

FAQ讨论程序员忘记做的特殊情况

#include< stdlib.h>。我包括这个标题,我没有做任何

显式演员:


#include< stdlib.h>

枚举ARRSIZE {MAXSIZE = 100};

struct dummy

{

int i;

};

int main(无效)

{


char * pc;

struct dummy * ptrDummy;


pc = malloc(MAXSIZE);

ptrDummy = malloc(sizeof(struct dummy));


返回0;

}


============输出============

/ home / arnuld / programs / C $ gcc -ansi -pedantic -Wall -Wextra test.c

/ home / arnuld / programs / C $ ./a.out

/ home / arnuld / programs / C $


malloc(size_t n)返回一个void指针,在我的程序中,我是

指定malloc返回指向2种不同类型的指针,我不是

得到关于<隐式演员>的任何警告。

它与C90有什么关系?



-
http://lispmachine.wordpress.com/

I have checked the FAQ: http://c-faq.com/malloc/mallocnocast.html
FAQ discusses a special case when programmer has forgotten to do
#include <stdlib.h>. I am including this header and I am not doing any
explicit cast:

#include <stdlib.h>
enum ARRSIZE { MAXSIZE = 100 };
struct dummy
{
int i;
};
int main( void )
{

char *pc;
struct dummy *ptrDummy;

pc = malloc( MAXSIZE );
ptrDummy=malloc(sizeof(struct dummy));

return 0;
}

============ OUTPUT ============
/home/arnuld/programs/C $ gcc -ansi -pedantic -Wall -Wextra test.c
/home/arnuld/programs/C $ ./a.out
/home/arnuld/programs/C $

malloc(size_t n) returns a void pointer and here in my program, I am
assigning malloc returned pointers to 2 different types and I am not
getting any warnings about <implicit cast>.
It has something to do with C90 ?


--
http://lispmachine.wordpress.com/

推荐答案

gcc -ansi -pedantic -Wall -Wextra test.c

/ home / arnuld / programs / C
gcc -ansi -pedantic -Wall -Wextra test.c
/home/arnuld/programs/C


./ a。 out

/ home / arnuld / programs / C
./a.out
/home/arnuld/programs/C




malloc(size_t n)返回一个void指针在我的程序中,我是

指定malloc返回指向2种不同类型的指针而且我不是

得到关于<隐式转换>的任何警告。

它与C90有什么关系?


-
http://lispmachine.wordpress.com/


这篇关于malloc()和隐式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆