07-24-2023, 04:56 AM
I have an assembly file (`asm.S`) which needs a constant `#define`'d in a C header file (`c_decls.h`). The header file contains C function declarations in addition to the `#define` I want. Unfortunately, `gcc` barfs when trying to compile the assembly file. For example,
**c_decls.h**
#ifndef __c_decls_h__
#define __c_decls_h__
#define I_NEED_THIS 0xBEEF
int foo(int bar);
#endif
**asm.S**
#include "c_decls.h"
.globl main
main:
pushl %ebp
movl %esp, %ebp
movl $I_NEED_THIS, %eax
leave
ret
**Output**
> \> gcc -m32 asm.S
c_decls.h: Assembler messages:
c_decls.h:6: Error: junk '(int bar)' after expression
c_decls.h:6: Error: suffix or operands invalid for 'int'
Is there a way to `#include` a C header file that contains function declarations in an assembly file? (Changing the header or moving/redefining the `#define` is not an option.)
**c_decls.h**
#ifndef __c_decls_h__
#define __c_decls_h__
#define I_NEED_THIS 0xBEEF
int foo(int bar);
#endif
**asm.S**
#include "c_decls.h"
.globl main
main:
pushl %ebp
movl %esp, %ebp
movl $I_NEED_THIS, %eax
leave
ret
**Output**
> \> gcc -m32 asm.S
c_decls.h: Assembler messages:
c_decls.h:6: Error: junk '(int bar)' after expression
c_decls.h:6: Error: suffix or operands invalid for 'int'
Is there a way to `#include` a C header file that contains function declarations in an assembly file? (Changing the header or moving/redefining the `#define` is not an option.)