5 Replies - 4917 Views - Last Post: 06 August 2011 - 12:23 AM Rate Topic: -----

#1 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

is there a way to expand all pre-proc statments in a header file?

Posted 05 August 2011 - 05:06 PM

ok so im working with LuaJIT trying to use the FFI to load allegro. the way the FFI works is you call a function which can parse user defined data types and function prototypes in C. it uses these prototypes so it can convert all the Lua values to C values before passing them to the c functions. i *could* add each prototype and structure as i need each function from allegro OR i could generate 1 monolithic header file, load it into a string then ask the foreign function interface of LuaJIT to parse that string. the issue at hand is that LuaJIT's FFI can't expand pre-processor directives. so i need a way to expand it into 1 big file. is there a way to do this?

Is This A Good Question/Topic? 1
  • +

Replies To: is there a way to expand all pre-proc statments in a header file?

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: is there a way to expand all pre-proc statments in a header file?

Posted 05 August 2011 - 07:43 PM

Look up your compiler options. There's an option for stopping at preprocessed file or keeping intermediate files.
Was This Post Helpful? 1
  • +
  • -

#3 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: is there a way to expand all pre-proc statments in a header file?

Posted 05 August 2011 - 08:15 PM

thanks!! i found -E for gcc, seems to have worked. the output file is 17000 lines long :)

there are a bunch of odd things in the output however.

things like this:
# 69 "allegro5/allegro.h" 2
# 2 "allegro5/allegro5.h" 2
# 1 "allegro.c" 2


im writing a small script to take them out.

edit: WIN!! IT WORKED!! thanks Oler1s!!

This post has been edited by ishkabible: 05 August 2011 - 08:27 PM

Was This Post Helpful? 0
  • +
  • -

#4 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1621
  • View blog
  • Posts: 3,079
  • Joined: 30-May 10

Re: is there a way to expand all pre-proc statments in a header file?

Posted 05 August 2011 - 11:11 PM

> there are a bunch of odd things in the output however.
> things like this:
> 1 # 69 "allegro5/allegro.h" 2
These indicate the positions in the original files, before the pre-processor expanded everything into one big file.
The first two being line number and filename (I don't know what the trailing 2 means yet).

So instead of meaningless "syntax error at line 8924545 of temp.i", you would get instead "syntax error at line 12 of prog.c"
Was This Post Helpful? 1
  • +
  • -

#5 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: is there a way to expand all pre-proc statments in a header file?

Posted 05 August 2011 - 11:37 PM

that makes sense, ive never seen them in C/C++ so it seemed rather strange to me. is it standard or compiler specif?
Was This Post Helpful? 0
  • +
  • -

#6 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1621
  • View blog
  • Posts: 3,079
  • Joined: 30-May 10

Re: is there a way to expand all pre-proc statments in a header file?

Posted 06 August 2011 - 12:23 AM

According to the standard, it should look like this

Quote

6.10.4 Line control
Constraints
1The string literal of a #line directive, if present, shall be a character string literal.
Semantics
2 The line number of the current source line is one greater than the number of new-line
characters read or introduced in translation phase 1 (5.1.1.2) while processing the source
file to the current token.
3 A preprocessing directive of the form
# line digit-sequence new-line
causes the implementation to behave as if the following sequence of source lines begins
with a source line that has a line number as specified by the digit sequence (interpreted as
a decimal integer). The digit sequence shall not specify zero, nor a number greater than
2147483647.
4 A preprocessing directive of the form
# line digit-sequence "s-char-sequenceopt" new-line
sets the presumed line number similarly and changes the presumed name of the source
file to be the contents of the character string literal.

The dropping of the word "line" from the hash lines would seem to be compiler specific.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1