错误:无效使用无效
Error: Invalid use of void
我正在使用C标头(hps_linux.h(编译C++源代码(main.cpp(。hps_linux.h 中的代码是:
#ifndef HPS_LINUX_H_
#define HPS_LINUX_H_
#include <stdbool.h>
#include <stdint.h>
#include "socal/hps.h"
int fd_dev_mem = 0;
void *h2f_lw_axi_master = NULL;
size_t h2f_lw_axi_master_span = ALT_LWFPGASLVS_UB_ADDR -ALT_LWFPGASLVS_LB_ADDR + 1;
size_t h2f_lw_axi_master_ofst = ALT_LWFPGASLVS_OFST;
#endif
hps_linux.h 包括 hps.h,它具有下一个定义:
#define ALT_LWFPGASLVS_OFST 0xff200000
#define ALT_LWFPGASLVS_ADDR ALT_CAST(void *, (ALT_CAST(char *, ALT_HPS_ADDR) + ALT_LWFPGASLVS_OFST))
#define ALT_LWFPGASLVS_LB_ADDR ALT_LWFPGASLVS_ADDR
#define ALT_LWFPGASLVS_UB_ADDR ALT_CAST(void *, ((ALT_CAST(char *, ALT_LWFPGASLVS_ADDR) + 0x200000) - 1))
我的主要.cpp包括hps_linux.h。我像这样编译:
gcc -Wall -std=gnu99 hps_linux.c -o hps_linux.o
g++ -Wall -std=c++0x main.cpp -o main
它抛出下一个错误:
hps_linux.h: error: invalid use of 'void'
行内:
size_t h2f_lw_axi_master_span = ALT_LWFPGASLVS_UB_ADDR -ALT_LWFPGASLVS_LB_ADDR + 1;
当我用 C 编写的主文件(main.c(编译它时,它可以工作。
查看此处的源代码,我们有:
#ifdef __ASSEMBLY__
# define ALT_CAST(type, ptr) ptr // <-- not (ptr)???
#else
# define ALT_CAST(type, ptr) ((type) (ptr))
#endif /* __ASSEMBLY__ */
现在,我们有:
size_t h2f_lw_axi_master_span = ALT_LWFPGASLVS_UB_ADDR - ALT_LWFPGASLVS_LB_ADDR + 1;
部分扩展宏,我们有:
size_t h2f_lw_axi_master_span = ALT_CAST(void *, ALT_CAST(char *, ...)) - ALT_CAST(void *, ALT_CAST(char *, ...)) + 1;
现在,如果设置了__ASSEMBLY__
,则此行为:
size_t h2f_lw_axi_master_span = ... - ... + 1;
两个...
表达式都是整数,所以这没关系。但是,如果未设置__ASSEMBLY__
,则此行为:
size_t h2f_lw_axi_master_span = (void *) (...) - (void *) (...) + 1;
没有定义减去两个 void 指针,因此编译器放弃了。
因此,您需要确保定义了__ASSEMBLY__
;一种方法是:
g++ -Wall -D__ASSEMBLY__ -std=c++0x main.cpp -o main
但是,这可能会导致问题,因为您应该依靠早期的头文件来正确设置它。
更新:快速搜索 git 存档不会显示正在设置__ASSEMBLY__
,并且给定名称表明它应该是内置编译器......
相关文章:
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- what(): basic_string::_M_construct 空无效错误
- C++ Linux 运行时basic_string::_M_construct null 无效错误
- 调用boost v1.58中的函数时出现模板名称使用无效错误
- 对象分配-成员函数的使用无效错误
- 从 WindowsAPI 调用 NetLocalGroupAddMembers 时,安全 ID 结构无效错误
- 为什么映射迭代器显示基本操作数无效错误
- 获取数组类型的无效错误
- 调用 vector.erase() 函数时指针操作无效错误
- C++:basic_string::_M_construct 空,对于图形 BFS 算法无效错误
- C++运行程序后给我 basic_string::_S_construct null 无效错误
- 使用 std::vector 时抽象类类型"Shape"的新表达式无效错误
- mmap 错误:分段错误/指针无效错误
- 从字符到字符编译器的转换无效错误
- 恒常性添加无效?错误:无法使用字符**初始化常量字符**
- 二进制表达式的操作数无效错误消息
- "从'文件* {aka _iobuf}'到'int'的转换无效"错误
- 在 boost 中序列化二进制数据失败,并出现"签名无效"错误
- 基类 T 无效错误
- 从“常量字符*”到“字符*”的转换无效错误