本文介绍了将void *转换为void **?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我有一个问题听起来很基本。 我的结构很简单: struct simple { void * buffer; }; typedef struct simple简单; 在我的函数中我这样做: void do_Something(){ Simple * simp_struct; simp_struct-> buffer = malloc(10 * sizeof(int *)); call_func((void **)((int **)(simp_struct - >缓冲区))); .... } 函数call_func有这个原型: call_func(void ** buf); 我对这段代码感到困惑: call_func((void **) ((int **)(simp_struct-> buffer))); 这个结构是什么意思?如何将simp_struct->缓冲区 (这是一个void *)强制转换为int **,然后将 强制转换为void **并传递给call_func? Rgds。 Mirage 解决方案 应该是这个: for(i = 0; i< 10; i ++) call_func((void **)((int **)simp_struct-> ;缓冲区+ i)); 我的问题依然如故。以上 构造的含义是什么意思? Rgds。 Mirage 这意味着你不会(或者写不出来的人)了解什么铸件 for。 - Richard Heathfield Usenet是一个奇怪的地方 - dmr 29/7/1999 http://www.cpax.org.uk 电子邮件:rjh在上面的域名(但显然放弃了www) - 原型是其克隆的超类型。 - maplesoft Hi All,I have a question which might sound very basic.I have a simple structure:struct simple{void *buffer;};typedef struct simple Simple;In my function I do this:void do_Something(){Simple *simp_struct;simp_struct->buffer = malloc(10 * sizeof(int *));call_func((void **)((int **)(simp_struct->buffer)));....}The function call_func has this prototype:call_func(void **buf);I am confused with this piece of code:call_func((void **)((int **)(simp_struct->buffer)));What does this construct mean? How is that simp_struct->buffer(which is a void *) is being cast to a int** followed by acast to void ** and passed to call_func ?Rgds.Mirage 解决方案should be this:for(i=0; i<10 ;i++)call_func((void **)((int **)simp_struct->buffer + i));My question remains the same. What does the aboveconstruct mean?Rgds.MirageIt means you don''t (or whoever wrote it doesn''t) understand what casting isfor.--Richard Heathfield"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.ukemail: rjh at above domain (but drop the www, obviously)--Prototypes are supertypes of their clones. -- maplesoft 这篇关于将void *转换为void **?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 05:36