Comments (1)
Original comment date: 2008-07-15T22:03:51-0700
I believe this is a problem with CPP and nested conditionals on Leopard. Using OSX 10.5.2, with
cpp --version
i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)
running cpp (not c2hs) on this text
#if 1
#if 1
int foo1();
#else
int foo2();
#endif
#else
int bar();
#endif
yields this result:
# 1 "foo2.chs"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo2.chs"
#if 1
int foo1();
#else
int foo2();
#endif
using #ifdef instead of #if seems to make no difference.
I don't know yet if this is fixed in 10.5.4, or by installing a newer gcc.
cpp (gcc-4.0.1 on leopard) doesn't process indented preprocessor directives. Maybe there's a flag for cpp which circumvents this problem, I don't know.
As the documentation (man page) of cpp seems to be out-of-date too, I'd suggest to use ghc -E
instead.
That is, invoke c2hs this way
c2hs -c ghc -C -E ...
Here's a small example once again documenting the problem:
$ cat test.h
#ifdef FOO
#endif
#ifdef FOO
#endif
$ cpp test.h
# 1 "test.h"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.h"
#ifdef FOO
#endif
$ gcc -E test.h
# 1 "test.h"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.h"
best regards, benedikt
I'm sorry, this should read:
...
I'd suggest to use gcc -E instead.
That is, invoke c2hs this way
c2hs -c gcc -C -E ...
...
This should actually work:
c2hs -c gcc -C "-E -x c" ...
This causes c2hs to execute
gcc -x=c -E -x c
such that -x c
(use C as language) overrides the invalid -x=c
flag.
The long story:
On Mac Os X (10.5), cpp is a shell script supplied for backwards compatiblity:
$ head -n 11 /usr/bin/cpp
#!/bin/sh
#
# Transitional front end to CCCP to make it behave like (Reiser) CCP:
# specifies -traditional
# doesn't search gcc-include
#
# Please beware that this program exists only to provide legacy BSD
# software access to cccp. Direct access to the C pre-processor
# is deprecated; it is only supported for use by the cc(1) C
# compiler. Use of cccp for anything other than C code is a bad
# idea. Don't do it. If you want a macro processor, use m4(1).
-traditional
implies that preprocessor directives have to start at the first column of a file.
When invoking cpp on Mac Os X, you're /roughly/ executing
gcc -E -traditional -x c ...
Therefore, one should use ghc -E
on darwin9 instead of cpp
, and if we need to use cpp
, one shouldn't pass -x=c
to the preprocessor.
benedikt
Patch to use gcc -E instead of cpp on darwin
Now using gcc -E on darwin. Probably should use it everywhere.
from c2hs.
Related Issues (20)
- Hackage version of c2hs fails to build with GHC-8.8.4 or 8.10.2 HOT 6
- pseudo block c and enum, creates wrong line counting
- Release schedule HOT 1
- Loosen bounds on language-c HOT 1
- Lexical error ! The character '#' does not fit here HOT 8
- Hackage tarball lacks tests
- Placeholder: removing `/=` from `Eq` HOT 2
- Haddock comments on enum constructors
- c2hs fails to produce the correct alignment HOT 14
- One more error with macos and time.h HOT 2
- capi calling convention
- Fails on Darwin with "clang: error: no input files"
- Paper Link Broken HOT 1
- _Bool type is broken
- Release a version where `cabal test` succeeds
- The symbol `[' does not fit here.
- "The symbol _Alignas does not fit here" when compiling with nvidia cuda.
- c2hs confused by clang headers on the Windows platform HOT 5
- Linker error with sublibraries and `__c2hs__wrapped__`-functions
- "Syntax error ! The symbol `;' does not fit here" while parsing /usr/include/bits/floatn-common.h:214 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c2hs.