简体   繁体   English

为什么我在 C 的枚举中收到“错误:错误指令”?

[英]Why am I getting “Error: bad instruction” in an enum in C?

This is weird and doesn't have any sense to me.这很奇怪,对我没有任何意义。 I added the following enum in a .h file u-boot:我在 .h 文件 u-boot 中添加了以下枚举:

typedef enum LP5521_Patterns_Tag
{
  LP5521_EB_ALL_GOOD,
  LP5521_EB_CLEAR_ALL,
  LP5521_EB_CONNECTED_TO_INTERNET,
  LP5521_EB_ENERGY_BRIDGE_FOUND,
  LP5521_EB_NO_SIGNAL,
  LP5521_EB_PLUGGED_IN,
  LP5521_EB_POOR_CONNECTION,
  LP5521_EB_SERACH_WIFI,
  LP5521_SET_COLOR,
  LP5521_SET_CURRENT,
  LP5521_SET_COLOR_CURRENT,
  LP5521_PATTERNS_TOTAL
}LP5521_Patterns_T;

But then when I try to compile it I get the following errors:但是当我尝试编译它时,我收到以下错误:

include/configs/lp5521.h: Assembler messages:
include/configs/lp5521.h:7: Error: bad instruction `typedef enum LP5521_Patterns_Tag'
include/configs/lp5521.h:8: Error: junk at end of line, first unrecognized character is `{'
include/configs/lp5521.h:9: Error: bad instruction `lp5521_eb_all_good,'
include/configs/lp5521.h:10: Error: bad instruction `lp5521_eb_clear_all,'
include/configs/lp5521.h:11: Error: bad instruction `lp5521_eb_connected_to_internet,'
include/configs/lp5521.h:12: Error: bad instruction `lp5521_eb_energy_bridge_found,'
include/configs/lp5521.h:13: Error: bad instruction `lp5521_eb_no_signal,'
include/configs/lp5521.h:14: Error: bad instruction `lp5521_eb_plugged_in,'
include/configs/lp5521.h:15: Error: bad instruction `lp5521_eb_poor_connection,'
include/configs/lp5521.h:16: Error: bad instruction `lp5521_eb_serach_wifi,'
include/configs/lp5521.h:17: Error: bad instruction `lp5521_set_color,'
include/configs/lp5521.h:18: Error: bad instruction `lp5521_set_current,'
include/configs/lp5521.h:19: Error: bad instruction `lp5521_set_color_current,'
include/configs/lp5521.h:20: Error: bad instruction `lp5521_patterns_total'
include/configs/lp5521.h:21: Error: junk at end of line, first unrecognized character is `}'

I notice that at the top it says Assembler messages but I don't understand either.我注意到在顶部它说汇编消息,但我也不明白。 There is a .c file that I already added that contain a bunch of typedef enums and I'm not getting any errors in those.我已经添加了一个 .c 文件,其中包含一堆 typedef 枚举,但我没有收到任何错误。

Could anyone please help me to figure out what is going on here?谁能帮我弄清楚这里发生了什么?

I don't know if this helps but I'm adding some code to u-boot and cross-compiling for imx6.我不知道这是否有帮助,但我正在向 u-boot 和 imx6 交叉编译添加一些代码。

Thank you!!谢谢!!

U-boot contains a lot of CPP pre-processed assembly files (ie .S rather than .s ); U-boot 包含大量的 CPP 预处理汇编文件(即.S而不是.s ); the board config header is probably the one thing that's included in just about everything (C files, assembly files, linker scripts) as it generally defines not just options but board-specific physical addresses, etc.板配置头可能是包含在几乎所有内容(C 文件、汇编文件、链接器脚本)中的一件事,因为它通常不仅定义选项,还定义板特定的物理地址等。

Ergo putting anything other than #defined symbols in there is pretty much asking for trouble. Ergo 把除 #defined 符号以外的任何东西都放在里面几乎是在自找麻烦。

Wrap this enum like this :像这样包装这个枚举:

  #if !defined(__ASSEMBLER__) 

  typedef enum LP5521_Patterns_Tag
  {
  LP5521_EB_ALL_GOOD,
  LP5521_EB_CLEAR_ALL,
  LP5521_EB_CONNECTED_TO_INTERNET,
  LP5521_EB_ENERGY_BRIDGE_FOUND,
  LP5521_EB_NO_SIGNAL,
  LP5521_EB_PLUGGED_IN,
  LP5521_EB_POOR_CONNECTION,
  LP5521_EB_SERACH_WIFI,
  LP5521_SET_COLOR,
  LP5521_SET_CURRENT,
  LP5521_SET_COLOR_CURRENT,
  LP5521_PATTERNS_TOTAL
  }LP5521_Patterns_T;

  #endif

defining _ ASSEMBLER _ symbol for Assembler and it should work.为 Assembler 定义 _ ASSEMBLER _ 符号,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会出现此错误? “信号:非法指令(核心转储)” - Why am I getting this error? "signal: illegal instruction (core dumped)" 为什么在C语言中出现此错误? - Why am I getting this error in C? 为什么我得到错误的文件描述符? - Why am I getting bad file descriptor? 将数字传递给期望枚举的函数时,为什么没有得到错误(或至少警告)? - Why am I not getting an error (or at least warning) when I pass a number to a function that is expecting an enum? 为什么我在C ++中得到“错误:期望'}'”但在C中没有? - Why am I getting “error: expected '}'” in C++ but not in C? 为什么在文件范围内初始化枚举类型变量时出现错误? - Why am I getting error when enum type variable is initialized in file scope? 为什么尝试在c中打印矩阵时出现此错误? - Why am I getting this error when trying to print a matrix in c? 为什么我在 C 编程中遇到类型说明符错误? - Why am I getting type specifier error in C programming? 为什么我收到函数参数的未声明错误? (C) - Why am I getting an undeclared error for a function argument? (C) 为什么在C中使用堆内存时出现运行时错误? - Why I am getting a runtime error on using heap memory in c?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM