Saturday, March 18, 2023
HomeGolangCommon and also typecasting - Obtaining Aid

Common and also typecasting – Obtaining Aid

Hi there!
I wish to create a straightforward approach to transform GO fundamental kind (int( 8/16/32)/ uint( 8/16/32)) to cgo kind ( C.uint e.t.c.)
I wish to make use of generics however fulfilled an issue with type-casting.
see the complying with code:

// wrapCType is a common approach to transform GOTYPE (int32/float32 e.t.c.) right into CTYPE (c_int/ c_float e.t.c.).
func wrapCType[CTYPE any, GOTYPE any]( goValue * GOTYPE) (covered * CTYPE, finisher func()) {
if goValue!= nil {
cValue:= CTYPE( any kind of(* goValue)).
covered = && cValue.
finisher = func() {
* goValue = GOTYPE( any kind of( cValue)).
} else {
finisher = func() {}



Most Popular

Recent Comments