void *到char **的转换无效 [英] Invalid converstion from void* to char**

查看:1116
本文介绍了void *到char **的转换无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一段时间,因为我搞砸C代码。

It has been a while since I messed with C code.

在使用gcc编译Ubuntu下的C代码时,出现以下错误。

I am getting the following error when compiling C code under Ubuntu using gcc.

我用来编译代码的命令是(如果这些错误是由于我使用的编译器,请让我知道如何使它消失) p>

The command I am using to compile code is (if these errors are because of compiler I am using, please let me know how to make that go away):

gcc -o runnable mycode.C 




错误:从'void *'到'char **'的无效转换

error: invalid conversion from ‘void*’ to ‘char**’

第39行是:

sequence=malloc(sizeof(char *)*seqNum);

序列声明为:

char **sequence;

seqNum声明为:

seqNum is declared as:

int seqNum


推荐答案

strong> Added:对于Arron的实际问题的禁食解决方案是由sgm在评论中提供的。下面的文本是准确的,希望有帮助,但对手头的问题的第二速率解决方案。

Added: The fasted solution to Arron's actual problem is provided by sgm in a comment. The text below is all accurate, and hopefully helpful, but a second rate solution to the problem at hand.

是非常僵硬的指针转换(你使用的是c ++编译器?),添加一个显式转型

Your compiler is being very stiffnecked about pointer casts (are you using a c++ compiler?), adding an explicit cast like

sequence=(char**)malloc(sizeof(char *)*seqNum);

应该使错误消失。或者,您也许能够说服编译器使用某种类似于

should make the error go away. Alternately you might be able to convince the compiler to go easy on you with some kind of option like

$(CC) --lighten-up-baby code.c

这可能是更好的,如果这是在某些第三方代码你真的不想黑客。阅读您的编译器文档以找到所需的选项。因为所有的 gcc 我手头上(版本4.0和4.2)是很高兴的代码,我不是一个好地方提供交换机的建议,行为关闭。

which might be preferable if this is in some third party code that you don't really want to hack. Read your compiler documentation to find the option you want. Since all the gccs I have on hand (versions 4.0 and 4.2) are happy with that code, I'm not in a good place to offer advice on switches to turn this behavior off.

这篇关于void *到char **的转换无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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