problems with FFI including h files

Sven Panne Sven.Panne@informatik.uni-muenchen.de
Sat, 01 Jun 2002 12:43:51 +0200


Alastair Reid wrote:
 > Any time you take two large C programs/libraries and try to merge
 > them, you're likely to run into preprocessor (or compiler) related
 > errors like those you describe. [...]

Sad, but very true! And GHC's headers are not very nice in this respect:

    panne@jeanluc:~> grep '#define [^ \t][^ \t] ' /usr/lib/ghc-5.03/include/*
    /usr/lib/ghc-5.03/include/PrimOps.h:#define C 0
    /usr/lib/ghc-5.03/include/PrimOps.h:#define R 1
    /usr/lib/ghc-5.03/include/PrimOps.h:#define C 1
    /usr/lib/ghc-5.03/include/PrimOps.h:#define R 0
    panne@jeanluc:~> grep '#define [^ \t][^ \t] ' /usr/lib/ghc-5.03/include/*
    /usr/lib/ghc-5.03/include/Regs.h:#define R1 (BaseReg->rR1)
    /usr/lib/ghc-5.03/include/Regs.h:#define R2 (BaseReg->rR2)
    /usr/lib/ghc-5.03/include/Regs.h:#define F1 (BaseReg->rF1)
    /usr/lib/ghc-5.03/include/Regs.h:#define F2 (BaseReg->rF2)
    /usr/lib/ghc-5.03/include/Regs.h:#define F3 (BaseReg->rF3)
    /usr/lib/ghc-5.03/include/Regs.h:#define F4 (BaseReg->rF4)
    /usr/lib/ghc-5.03/include/Regs.h:#define D1 (BaseReg->rD1)
    /usr/lib/ghc-5.03/include/Regs.h:#define D2 (BaseReg->rD2)
    /usr/lib/ghc-5.03/include/Regs.h:#define L1 (BaseReg->rL1)
    /usr/lib/ghc-5.03/include/Regs.h:#define Sp (BaseReg->rSp)
    /usr/lib/ghc-5.03/include/Regs.h:#define Su (BaseReg->rSu)
    /usr/lib/ghc-5.03/include/Regs.h:#define Hp (BaseReg->rHp)

And so on...

SimonM: What about a "poor man's" namespace, i.e. prefixing every macro,
type, etc. with "GHC"/"ghc"? OpenGL, GLUT, GTK, etc. do a similar thing,
and although it's a primitive measure, it's very effective.

Cheers,
    S.