CPP and INLINE pragmas

Since CPP mode removes newlines in the out macro expansion. It appears to be impossible to have a macro expand to a function with an INLINE pragma since it appears to need to be in its own line. For example: #define GETHOSTWORD(name, m, type) \ {-# INLINE name #-} \ name :: m type ; \ name = getPtr (sizeOf (undefined :: type)) \ Does work (since you can't follow the INLINE pragma with anything else on the same line. Likewise: #define GETHOSTWORD(name, m, type) \ name :: m type ; \ name = getPtr (sizeOf (undefined :: type)) \ {-# INLINE name #-} Also doesn't work since the INLINE needs to start at the beginning of a line. Has anyone a workaround for this, or a way to get the preprocessor to output a newline? Cheers AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641

Adam Langley wrote:
Since CPP mode removes newlines in the out macro expansion. It appears to be impossible to have a macro expand to a function with an INLINE pragma since it appears to need to be in its own line.
that's because INLINE uses layout like everything else, so you can use semicolons for it too.
For example:
#define GETHOSTWORD(name, m, type) \ {-# INLINE name #-} \ name :: m type ; \ name = getPtr (sizeOf (undefined :: type)) \
something like #define GETHOSTWORD(name, m, type) \ {-# INLINE name #-} ; \ name :: m type ; \ name = getPtr (sizeOf (undefined :: type)) \ ~Isaac

"Adam Langley"
Has anyone a workaround for this, or a way to get the preprocessor to output a newline?
You can use cpphs with the --layout flag, to preserve newlines in macro expansion. http://haskell.org/cpphs For instance, with ghc you need to add the following flags: ghc -cpp -pgmPcpphs -optP--cpp -optP--layout Regards, Malcolm

Thanks Isaac and Malcolm. That neatly solves all my problems! AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641
participants (3)
-
Adam Langley
-
Isaac Dupree
-
Malcolm Wallace