无法在 C 中使用 * void 指针初始化结构

标签 c visual-studio visual-studio-2012

我有结构:

typedef struct node {
  char *question;
  struct node  *no;
  struct node  *yes;
} node;

尝试为结构指针获取内存:

node *n = malloc(sizeof(node));

编译错误:

 a value of type "void *" cannot be used to initialize an entity of type "node *"   

我告诉 visual studio 2012 编译 C 代码 - Compile as C Code (/TC)

如何解决这个问题?

最佳答案

malloc()void*赋给你的node*是100%有效的C,你的问题肯定是100%由于您的编译器出于某种原因将您的代码读取为 C++,即使您指定了 /TC

关于无法在 C 中使用 * void 指针初始化结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24984497/

相关文章:

c - 动态链接器是 Linux 系统上内核或 GCC 库的一部分吗?

c - 读取以 CR 结尾的关键字文本文件

c++ - native C++ 和 Windows 平板电脑

c# - Visual Studio 2012 构建失败但错误列表中没有错误

c - 字符串化括号消除

visual-studio - 当我更改配置设置时,Visual Studio会生成 “Settings1.Designer.vb”

mongodb - 无法在 Visual Studio 2013 中引用 Hangfire.Mongo

wpf - Visual Studio : How to write Editor Extensions with WPF

c# - 如何使自定义提取规则属性数据驱动?

c - 我的子进程无法使用 Pipe 从父进程接收最后一个值