Comments (4)
I haven't really checked but it's quite possible the bitfield handling is broken in cc
. I've run into several such issues and somehow bypassed them in ccir, for example. Once I will get [more] confident about the correctness of the bypass, I gues it's due to backport ccir
's hack to cc
.
However, please feel free to report any cc
issue directly at its issue tracker. No promises about when the fixes will come, but I'm currently becoming more and more dependent on [at least some] correctness of cc
, so bug reports are definitely welcome.
from c-for-go.
@cznic as far as I can tell, the interpretation of the bitfield is correct from cc's side. The problem is a difference between what c-for-go and cgo expect. From a careful inspection of the error output (above); you can see that for some reason, even though the bitfield's type is an int, if the bitfield with is 8 - even though the type is an int, cgo expects you to assign a uint8
to it! Not a C.uint8_t
, but a go uint8
. I think this is a surprising feature of cgo and I can't find it documented anywhere.
Separate thought:
I didn't think to check non-multiples of 8, but in that case I get:
typedef struct {
int i : 1;
int j : 7;
int k : 15;
int l : 31;
} Foo;
bitfield/cgo_helpers.go:159: x.refb43e23c1.i undefined (type *C.struct___0 has no field or method i)
bitfield/cgo_helpers.go:160: x.refb43e23c1.j undefined (type *C.struct___0 has no field or method j)
bitfield/cgo_helpers.go:161: x.refb43e23c1.k undefined (type *C.struct___0 has no field or method k)
bitfield/cgo_helpers.go:162: x.refb43e23c1.l undefined (type *C.struct___0 has no field or method l)
... which seems to suggest that CGo doesn't support odd-sized bitfields? Am I missing something here - is the above struct definition valid C?
from c-for-go.
Am I missing something here - is the above struct definition valid C?
Seems valid. I'm not aware of any requirement of the bitfileds to be of width a multiply of something.
from c-for-go.
I don't think it's just odd bitfield sizes. I think it might be any bitfields that are not powers of 2? From the cgo command documentation: "C struct fields that cannot be expressed in Go, such as bit fields or misaligned data, are omitted in the Go struct, replaced by appropriate padding to reach the next field or the end of the struct."
from c-for-go.
Related Issues (20)
- How to handle callback functions HOT 2
- unexpected identifier strtof32 HOT 2
- Best way to handle different include paths for different operating systems? HOT 1
- How to add a Framework? HOT 5
- How to keep int as int? HOT 2
- How to make int8_t from c to int8 in golang? HOT 1
- With the latest commit (c95ebd03aba931e7248a6011f86d822ab878d00c), c-for-go can no longer generate defines HOT 10
- Go Integer overflows translated from large C enum numbers HOT 5
- define pointer to function HOT 1
- type C.struct_ in strut and func HOT 1
- How to handle a function returning a struct as value
- Type translation does not respect systems data model HOT 1
- Verbose argument to print more logs
- Avoid lock / unlock for some function call
- Wiki need to be updated
- panic: unknown type _Float128 HOT 2
- Non int return function pointer not recognized
- Generator uses underlying type of typedef when used as a parameter
- Website down HOT 3
- It would be nice to at least have an example of the YML required in the readme since the website does not work 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 c-for-go.