英文:
golang casting to void type
问题
我知道在Go语言中,无返回值函数是不需要明确声明的,可以直接写成:
func foo(start int, end int) { ... }
那么在C语言中,有没有类似的强制转换为void的概念,以强调返回值不被使用呢?
(void) printf("hello world");
在Go语言中是否存在这样的概念(或等价的概念)呢?
英文:
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?
答案1
得分: 3
Go语言不支持类型转换,也没有void类型,因此没有与您所要求的功能等效的方法。
为了记录您有意忽略返回值的函数的目的,您可以使用空白标识符来丢弃该值:
_, _ = fmt.Printf("Hello world")
英文:
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")
答案2
得分: 2
在Go语言中不存在这个概念(或等价概念)。
英文:
> [D] oes this notion (or equivalent) exist in go?
No.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论