I have a little piece of code which has a statement void();
int main()
{
void( ); // 1: parses fine in GCC 5.4.0 -Wpedantic
// void; // 2: error declaration does not declare anything
}
What is 1 void()
exactly?
What makes 1 void()
different from 2 void;
?
I have read already:
But I am curious if the loose statement void(); is different from one of those (and why of course)
Having no legal effect from the start. Thus, a void contract is invalid from the start of its purported closing (having no legal effect, it does not change the legal relationship between the parties involved).
A void contract is a contract that isn't legally enforceable, starting from the time it was created. While both a void and voidable contract are null, a void contract cannot be ratified. In a legal sense, a void contract is treated as if it was never created and becomes unenforceable in court.
Something that is void is officially considered to have no value or authority. The vote was declared void.
Void: Not an actual contract and is unenforceable. Valid: Legally binding and enforceable in a court of law.
void;
is an error because there is no rule in the language grammar which matches that code. In particular, there is no rule type-id
;
,
However, the code void()
matches two grammar rules:
type-id
.postfix-expression
, with the sub-case being simple-type-specifier
(
expression-list-opt
)
. Now, the parser needs to match void();
to a grammar rule. Even though void()
matches type-id
, as mentioned earlier there is no rule that would match type-id
;
. So the parser rejects the possible parsing of void()
as type-id
in this context, and tries the other possibility.
There is a series of rules defining that postfix-expression
;
makes a statement. So void()
is unambiguously parsed as postfix-expression in this context.
As described by the other answers you linked already, the semantic meaning of this code as a postfix-expression is a prvalue of type void
.
Related link: Is sizeof(int())
a legal expression?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With