简体   繁体   English

golang 转换为 void 类型

[英]golang casting to void type

I know that void functions in go are written without mentioning it:我知道 go 中的void 函数是在没有提及的情况下编写的:

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

What about the notion of casting to void in C, to emphasize returned value is not used: C 中的强制转换为 void的概念怎么样,强调没有使用返回值:

(void) printf("hello world");

does this notion (or equivalent) exist in go? go 中是否存在这个概念(或等价物)?

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. Go 不支持类型转换,并且 Go 没有任何 void 类型,因此没有与您要求的功能等效的功能。

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:为了记录您有意忽略返回某些内容的 function 的返回值,您可以使用空白标识符,它只是丢弃该值:

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

[D] oes this notion (or equivalent) exist in go? [D] go 中是否存在这个概念(或等价物)?

No.不。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM