I have populated a structure in go Lang, i want to pass this structure to C and i want to print contents of the structure populated in GO in C.
But when i try this i get following error.
could not determine kind of name for C.GetStruct
gcc errors for preamble:
./t32.go:5: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
Can anyone suggest what am doing wrong, am new to GO and am trying out sample GO to C interaction and C to GO interaction.
#ifndef __T32_H__
#define __T32_H__
typedef struct {
int Address_0
int Address_1
int Address_2
int Address_3
} Address;
int GetStruct( Address* );
#endif /* __T32_H__ */
The code you have supplied is wrong in many areas.
You are not defining your struct or function in C properly, and you are also not accessing its members correctly. You are also attempting to use a struct named Breakpoint which does not exist in the C code you provided.
If you read the cgo documentation, you would know you need to call the C struct using C.struct_Address
unsafe.Pointer is void * in C, and no idea why your type casting to a struct your C function is not expecting.
#ifndef __T32_H__
#define __T32_H__
struct Address {
int Address_0;
int Address_1;
int Address_2;
int Address_3;
};
int GetStruct(struct Address *addr);
#endif /* __T32_H__ */