Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not true that unlabelled blocks are always statements as they can be used on the right side on an assignment and result in a type of
void
It is also not true that labelled blocks are always expressions, the label can be used only for
break
andcontinue
control flow without any return value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I'm very new to Zig so this may be a silly question, but is the block evaluating to void construct useful? Writing something like that seems like a mistake on the programmers side (and the compiler shouldn't allow it).
Also please take my comments with a grain of salt, I'm very new at Zig. Actually @zenspider was helping me try to understand why my
if
expression wasn't working, and it turned out to be due to the fact that blocks aren't expressions (IOWconst x = if () { ... }
is very different thanconst x = if () ...
, and I didn't understand that)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its the only way to initialize a void field. This is common practice in particular if you're using comptime to turn a field "on" or "off". i.e.:
A void field takes up no space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it is one of two ways to initialize a void value. The second way is the void literal '
void{}
'.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, this makes a lot of sense. Thank you for taking the time to explain, I really appreciate it!!