GHC, CPP and stringize

Neil Brown nccb2 at kent.ac.uk
Fri Oct 30 13:17:16 EDT 2009


Hi,

The GHC manual says that if you pass -cpp to GHC, it runs the C 
preprocessor, "cpp" on your code before compilation 
(http://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#c-pre-processor).  
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*
putStrLn
Hello!


=====

What am I missing?

Thanks,

Neil.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20091030/e735c89d/attachment.html


More information about the Glasgow-haskell-users mailing list