Is it possible to reference C enums from an assembly file?

删除回忆录丶 提交于 2019-12-01 19:39:39

No there isn't.
You could do something like:

enum_support.h

#ifdef __ASSEMBLER__
#define ENUM_START
#define ENUM_VALUE(key,value) .equ key,value
#define ENUM_END(typename)
#else
#define ENUM_START typedef enum{
#define ENUM_VALUE(key,value) key=value,
#define ENUM_END(typename)} typename;
#endif

syscalls.h

#include "enum_support.h"

ENUM_START
ENUM_VALUE(OPEN_FILE,0)
ENUM_VALUE(READ_FILE,1)
ENUM_VALUE(CLOSE_FILE,2)
ENUM_END(Syscall)

And then have test.c and test.s include syscalls.h

gcc -c test.c
gcc -c test.s

Not sure it's very helpful, but I don't know any other way to share enums (which are non existent in assembly).
You could do cpp test.c or cpp -D__ASSEMBLER__ test.s to see the emitted code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!