Commit 0a63cdff authored by Alexander Hirsch's avatar Alexander Hirsch
Browse files

Replace 2nd goto example

parent 1de5990c
......@@ -404,23 +404,25 @@ loopexit:
char *buffer = malloc(256);
for (int i = 0; i < numberOfThings; i++) {
if (giveMeThing(i, buffer) != OK)
goto error;
if (processThing(buffer) != OK)
goto error;
if (dispatchThing(i, buffer) != OK)
goto error;
bool do_something(void)
bool result = false;
ResourceA resource_a;
if (!acquire_resource_a(resource_a)) goto error1;
ResourceB resource_b;
if (!acquire_resource_b(resource_b)) goto error2;
ResourceC resource_c;
if (!acquire_resource_c(resource_c)) goto error3;
return OK;
result = do_something_with_resources(resource_a, resource_b, resource_c);
return OOPS;
error3: release_resource_c(resource_c); // only allowed if acquired
error2: release_resource_b(resource_b);
error1: release_resource_a(resource_a);
return result;
## Multiple Source Files
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment