Posted by Anonymous on Thu 16 Apr 11:37
report abuse | View followups from pwet, pwet, Anonymous, Anonymous, Anonymous, Bruno, sdf, Fred, robkinyon, cschneid, phildpayne, MrKotter, KCR, Anonymous, Anonymous, Patrick E, spinlock, skraps, peck, Boo, Anonymous, rabidsnail, tlouden, Anonymous, Jonathan, chris, fz, nage, Robert, Abram Nichols, Anonymous, Anonymous, SoCo_cpp, Anonymous, Anonymous, RachelB, sdeken, Edgar, Anonymous, Sumudu, dolob, Jeff, Anonymous, i41welcomerlordcthulhu, Tim, Anonymous, redd12314512346346, tga, Anonymous, Anonymous, zarko_a, Anonymous, Axel, bisserke, JohnnyQuest, Tim Reynolds, Anonymous, Anonymous, Keith Thompson, Anonymous, liang, Max, george obrien, Way, AlexDW and Allan Wind | download | new post
- /* Problem: Inefficient and confusing */
- int foo(int bar)
- {
- int return_value = 0;
- int doing_okay = 1;
- doing_okay = do_something( bar );
- if (doing_okay)
- {
- doing_okay = init_stuff();
- }
- if (doing_okay)
- {
- doing_okay = prepare_stuff();
- }
- if (doing_okay)
- {
- return_value = do_the_thing( bar );
- }
- return return_value;
- }
- /* Problem: Getting murdered by PHB's for using goto */
- int foo(int bar)
- {
- if (!do_something( bar )) {
- goto error;
- }
- if (!init_stuff( bar )) {
- goto error;
- }
- if (!prepare_stuff( bar )) {
- goto error;
- }
- return do_the_thing( bar );
- error:
- return 0;
- }
- /* Problem: Too many nested blocks, horrible */
- int foo(int bar)
- {
- int return_value = 0;
- if (do_something( bar )) {
- if (init_stuff( bar )) {
- if (prepare_stuff( bar )) {
- return_value = do_the_thing( bar );
- }
- }
- }
- return return_value;
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.