Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
bitfield
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Apr 3, 2022
1 parent a03115e commit 125d403
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/goplus/c2go
go 1.16

require (
github.com/goplus/gox v1.9.10
github.com/goplus/gox v1.9.11
github.com/json-iterator/go v1.1.12
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/goplus/gox v1.9.10 h1:b0d+1avchoYswNd28o1mYnk49OjLJ/3A57oERCifFyM=
github.com/goplus/gox v1.9.10/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
github.com/goplus/gox v1.9.11 h1:2wf7bQO6c0Z5JNO8pTqQRX3BPRIJYSum0savgLnso08=
github.com/goplus/gox v1.9.11/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
Expand Down
29 changes: 29 additions & 0 deletions testdata/bitfield/bitfield.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

typedef struct {
unsigned short a :1,
b :2,
:3,
c :5;
short x :1,
y :2,
:3,
z :5;
} foo;

int main() {
foo foo;
foo.a = 1;
foo.b = 3;
foo.c = 15;
foo.x = 1;
foo.y = 3;
foo.z = 15;
printf(
"foo.a = %d, foo.b = %d, foo.c = %d\n",
foo.a, foo.b, foo.c);
printf(
"foo.x = %d, foo.y = %d, foo.z = %d\n",
foo.x, foo.y, foo.z);
return 0;
}
29 changes: 29 additions & 0 deletions testdata/bitfield/libc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
"unsafe"
)

func gostring(s *int8) string {
n, arr := 0, (*[1 << 20]byte)(unsafe.Pointer(s))
for arr[n] != 0 {
n++
}
return string(arr[:n])
}

func printf(format *int8, args ...interface{}) int {
goformat := gostring(format)
for i, arg := range args {
if v, ok := arg.(*int8); ok {
args[i] = gostring(v)
}
}
fmt.Printf(goformat, args...)
return 0
}

func __swbuf(_c int, _p *__sFILE) int {
return _c
}
1 change: 1 addition & 0 deletions testdata/bitfield/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c2go ./bitfield.c

0 comments on commit 125d403

Please sign in to comment.