Another CPP gotcha for the manual

Daniel Trstenjak daniel.trstenjak at gmail.com
Mon Nov 4 09:29:50 UTC 2013


Hi Mark,


On Sun, Nov 03, 2013 at 03:01:32PM -0800, Mark Lentczner wrote:
> This does not appear to be the case, at least any more. The way GHC invokes gcc
> for c pre-processing only removes /*…*/ style comments, not the later // style:

Yes, I can reproduce your behaviour on my system and ghc seems to call cpp with
some options, because the default behaviour removes C++ style comments:

dan at machine ~> cat cpp.test 
/* comment */
code
// comment


dan at machine ~> cpp cpp.test 
# 1 "cpp.test"
# 1 "<command-line>"
# 1 "cpp.test"

code


I can't recall it exactly, if I had the C++ comment issue only with
cpphs, because cpp had problems with some Haskell code, or if I also
had the issue with cpp itself.


I just tried cpphs and its default behaviour removes the C++ style comments:

dan at machine ~> cat test.hs
(//) :: Double -> Double -> Double
a // b = a / b / b

main = print $ 1 // 2


dan at machine ~> ghci
Prelude> :set -cpp -pgmPcpphs -optP--cpp
Prelude> :l test
[1 of 1] Compiling Main             ( test.hs, interpreted )

test.hs:2:1:
    parse error (possibly incorrect indentation or mismatched brackets)
Failed, modules loaded: none.


That's a bit unfortunate, that the default behaviour of ghc using cpp and cpphs differs.


Greetings,
Daniel


More information about the ghc-devs mailing list