Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1089 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#include header with C declarations in an assembly file without errors?

#1
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.)
Reply

#2
Use the `-dM` option for `cpp` to get just the #defines out of your header files, and include that file instead.

cpp -dM c_decls.h > bare_c_decls.h

Now include `bare_c_decls.h` in your .S file. And if you can't change the #include in the .S file, generate the bare header files in another directory, and put that include path on your compiler/assembler command line, ahead of everything else.

And finally, you can wrap this all up in a makefile so your "bare" header files are generated automatically.
Reply

#3
That's simle:
In your .S file use

#define __ASSEMBLY__

In your .C file use

#undef __ASSEMBLY__

Then in .h file place condition


#ifdef __ASSEMBLY__
// here declarations only for assembler
#else
// here only for C
#endif
// and here - defines suitable for both




Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through