Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Alexander Hirsch
crap
Commits
0a63cdff
Commit
0a63cdff
authored
Oct 03, 2019
by
Alexander Hirsch
Browse files
Replace 2nd goto example
parent
1de5990c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
15 deletions
+17
-15
slides/c_slides.md
slides/c_slides.md
+17
-15
No files found.
slides/c_slides.md
View file @
0a63cdff
...
...
@@ -404,23 +404,25 @@ loopexit:
---
```
c
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
;
free
(
buffer
);
return
OK
;
result
=
do_something_with_resources
(
resource_a
,
resource_b
,
resource_c
);
error
:
free
(
buffer
);
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment