本文介绍了是sizeof(void())一个合法的表达式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从,我发现:

从,我发现:

无论如何,对于 sizeof 不评估它的操作数,我会说, sizeof(void())是一个法律表达式(实际上是GCC编译它,结果是1)。

另一方面,从在讨论 sizeof 时没有提到 void ,当提及大小为1的类型时,

Anyway, for sizeof does not evaluate it's operands, I would have said that sizeof(void()) was a legal expression (actually GCC compiles it and the result is 1).
On the other side, from here, void is not mentioned while discussing sizeof, neither when the types having size 1 are mentioned, nor in the list of the ones having an implementation defined size.

问题是: sizeof(void) ())一个法律表达式?

它保证有大小等于1?

或者是一个导致UB的法律表达式,所有?

The question is thus: is sizeof(void()) a legal expression?
Is it guaranteed to have size equal to 1?
Or is it a legal expression resulting in an UB and that's all?

推荐答案

void()是一个函数类型函数不需要参数并且不返回任何内容),因此它不是 sizeof()中的有效类型。

void() is a function type (it's a function which takes no arguments and returns nothing), so it's not a valid type in sizeof().

这篇关于是sizeof(void())一个合法的表达式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!