-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
Please everyone post links to your zig code that uses goto, so we won't remove the feature. Alternatively, post links to C code that uses goto, so we can assess if there's a more zig-like way to do it, or if goto is really the best solution for those cases.
I want real actual code here, not pseudocode examples. Please link to open source projects.
This discussion started in #346.
For reference, here's how you can do without goto:
- use
deferfor the try-finally pattern. - use
%deferfor the cleanup-on-error pattern. - use
while (true) { switch (state) { ...for cases where you want computed goto. Here's some existing discussion on that: labeled loops, labeled break, labeled continue #346 (comment) - use labeled
breakto jump forward and labeledcontinueto jump backward, placing loops where necessary. This is the plan for the C-to-Zig translator. This is the ugliest solution, but should always work when all else fails.
Froxcey and bonkmaykrQ
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.