Error: Invalid use of void
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))
我的 main.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 (main.c) 编译它时,它可以工作。
查看 source code here,我们有:
#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
但是,这可能会导致问题,因为您应该依靠早期的头文件来正确设置它。
Update:快速搜索 git 档案没有显示 __ASSEMBLY__
被设置,并且给出的名字表明它应该是一个编译器内置...
我正在使用 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))
我的 main.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 (main.c) 编译它时,它可以工作。
查看 source code here,我们有:
#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
但是,这可能会导致问题,因为您应该依靠早期的头文件来正确设置它。
Update:快速搜索 git 档案没有显示 __ASSEMBLY__
被设置,并且给出的名字表明它应该是一个编译器内置...