Initialize a Go struct wrapping a C type by calling the C initialization function before use, as the zero value is invalid for C libraries like GMP. In the provided gmp package, the doinit method checks an init flag and calls C.mpz_init on the underlying C pointer if the struct hasn't been initialized yet.
func (z *Int) doinit() {
if z.init {
return
}
z.init = true
C.mpz_init(&z.i[0])
}
Always call doinit (or a similar wrapper) at the start of any method that accesses the C struct fields to prevent crashes from using uninitialized C memory.