Home > Blockchain >  golang casting to void type
golang casting to void type

Time:11-30

I know that void functions in go are written without mentioning it:

func foo(start int, end int) { ... }

What about the notion of casting to void in C, to emphasize returned value is not used:

(void) printf("hello world");

does this notion (or equivalent) exist in go?

CodePudding user response:

Go doesn't support type casting, and Go doesn't have any void type, so there's no functional equivalent to what you're asking for.

For the purpose of documenting that you're intentionally ignoring the return value of a function that returns something, you can use the blank identifier, which simply discards the value:

_, _ = fmt.Printf("Hello world")

CodePudding user response:

[D] oes this notion (or equivalent) exist in go?

No.

  • Related