pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C pastebin - collaborative debugging tool View Help


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

  1. /* Problem: Inefficient and confusing */
  2. int foo(int bar)
  3. {
  4.         int return_value = 0;
  5.         int doing_okay = 1;
  6.         doing_okay = do_something( bar );
  7.         if (doing_okay)
  8.         {
  9.                 doing_okay = init_stuff();
  10.         }
  11.         if (doing_okay)
  12.         {
  13.                 doing_okay = prepare_stuff();
  14.         }
  15.         if (doing_okay)
  16.         {
  17.                 return_value = do_the_thing( bar );
  18.         }
  19.         return return_value;
  20. }
  21.  
  22. /* Problem: Getting murdered by PHB's for using goto */
  23. int foo(int bar)
  24. {
  25.         if (!do_something( bar )) {
  26.                 goto error;
  27.         }
  28.         if (!init_stuff( bar )) {
  29.                 goto error;
  30.         }
  31.         if (!prepare_stuff( bar )) {
  32.                 goto error;
  33.         }
  34.         return do_the_thing( bar );
  35. error:
  36.         return 0;
  37. }
  38.  
  39. /* Problem: Too many nested blocks, horrible */
  40. int foo(int bar)
  41. {
  42.         int return_value = 0;
  43.         if (do_something( bar )) {
  44.                 if (init_stuff( bar )) {
  45.                         if (prepare_stuff( bar )) {
  46.                                 return_value = do_the_thing( bar );
  47.                          }
  48.                 }
  49.         }
  50.         return return_value;
  51. }

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.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post