haskell / haskell/c2hs

#sizeof doesn't work on struct fields

Open
#171 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Haskell
Stars
211
Forks
52
PR merge metrics
No merged PRs in 30d

Description

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#}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.