GHC, CPP and stringize

Neil Brown nccb2 at
Fri Oct 30 13:17:16 EDT 2009


The GHC manual says that if you pass -cpp to GHC, it runs the C 
preprocessor, "cpp" on your code before compilation 
But why, in that case, does stringize not seem to work when the -cpp 
flag is given?

In my example, test.hs is using the C preprocessor with a simple macro 
to trace functions with their name.  Running GHC with -cpp gives an 
error, but if I run cpp on the file directly then feed it to GHC, I get 
no error:

*$ ghc --version*
The Glorious Glasgow Haskell Compilation System, version 6.10.3

*$ cat test.hs*
import Debug.Trace

#define TR(f) (trace #f f)

main :: IO ()
main = TR(putStrLn) "Hello!"

*$ ghc -cpp --make test.hs*
[1 of 1] Compiling Main             ( test.hs, test.o )

test.hs:6:14: Not in scope: `#'

*$ cpp test.hs*
# 1 "test.hs"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.hs"
import Debug.Trace

main :: IO ()
main = (trace "putStrLn" putStrLn) "Hello!"

*$ cpp test.hs > test-cpp.hs*

*$ ghc -cpp --make test-cpp.hs*
[1 of 1] Compiling Main             ( test-cpp.hs, test-cpp.o )
Linking test-cpp ...

*$ ./test-cpp*


What am I missing?


-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Glasgow-haskell-users mailing list