haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

#sizeof doesn't work on struct fields #171

Open jchia opened 8 years ago

jchia commented 8 years ago

Trying to c2hs the following Foo.chs fails with "The phrase '.' is not allowed here." I want to get back 10. Replacing #sizeof with #offsetof causes c2hs to succeed. I think #sizeof should evaluate similarly to sizeof in C++ (sizeof(Foo::bar)). (I don't know how it can be done straightforwardly in C.)

/* Foo.h */
struct Foo {
    char bar[10];
};
-- Foo.chs

#include "Foo.h"

module Foo where

sizeOfFooBar :: Int
sizeOfFooBar = {#sizeof Foo.bar#}