-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix partial array initialization #262
Comments
Excellent reference! 👍 |
@elliotchance It turns out that go behaves the same way in terms of partial array initialization. The rest of the array is assigned the zero-value for that type. The keyword here is array. The problem is that we convert C arrays to Go slices. Go https://play.golang.org/p/g2XcSacYz5 var a [4]int = [4]int{10,20}
fmt.Println(a[0],a[1],a[2],a[3]) // -> 10 20 0 0 If we convert arrays to slices (current c2go behavior): var a []int = []int{nil, 10, 20} // nil is the ArrayFiller
fmt.Println(a[0],a[1],a[2],a[3]) // -> 1 2 <arrayOutOfBounds> Should we convert C fixed arrays as Go fixed arrays instead of slices? |
Hmmm you bring up a good point. Fixed size arrays will have to be equivalent (fixed size) in Go, otherwise assigning to an index in the capacity would fail terribly. The alternative (to simplify pointers) is we could always use slices, but have slices preallocated when created. |
I think it is ok to use slices for pointers and strings, but my first impression is to convert C fixed-sized arrays to go fixed-sized arrays. I did not see that many partial initialization (like in the example), so I will refrain from making any changes until we confirm that it is necessary to transpile sqlite3.c. I would label this issue as a "low". |
int a[4] = {10, 20};
should be initialized as{10, 20, 0, 0}
C99 specs: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf, page 127, item 21
The text was updated successfully, but these errors were encountered: