Open andybalholm opened 5 years ago
I think it's more likely to be a bug with the transpires understanding of what is trying to happen.
If you write them as two separate statements does it produce a correct result?
If I separate the declaration of the type from the declaration of the variable from the declaration of the type, I get exactly the same result:
typedef struct {
int a[5];
} aStruct;
aStruct v = {{1, 2, 3, 4, 5}};
If I separate the initialization from the declaration, it isn't valid C, because initializer lists are only allowed in declarations:
typedef struct {
int a[5];
} aStruct;
aStruct v;
int main() {
v.a = {1, 2, 3, 4, 5};
}
Please try https://github.com/Konstantin8105/c4go
struct aStruct {
int a[5];
} v = {{1, 2, 3, 4, 5}};
//
// Package - transpiled by c4go
//
// If you have found any issues, please raise an issue at:
// https://github.com/Konstantin8105/c4go/
//
package main
// aStruct - transpiled function from GOPATH/src/templorary/rot.c:1
type aStruct struct {
a [5]int32
}
// v - transpiled function from GOPATH/src/templorary/rot.c:1
var v aStruct = aStruct{[5]int32{1, 2, 3, 4, 5}}
When there is an initializer list for an array in a struct, the transpiled program fails to compile with a type error. When an array is not in a struct, it transpiles to a slice, but when it's in a struct, it transpiles to an array. I assume this is to maintain the memory layout of the struct (?).
transpiles to
Which fails to compile because we're trying to assign a slice to an array.