GHC, CPP and stringize

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

On Fri, 2009-10-30 at 17:17 +0000, Neil Brown wrote:
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#...). But why, in that case, does stringize not seem to work when the -cpp flag is given?
#define TR(f) (trace #f f)
What am I missing?
That ghc uses cpp in traditional mode so it does not grok new ANSI C things like cpp string concatenation. As I understand it we have to use traditional CPP because some modern features break Haskell code. Really we should all move over to cpphs. Duncan
participants (2)
-
Duncan Coutts
-
Neil Brown