Is getopt() standard C? etc.

From: José de Paula (jose_de_paula_at_ig.com.br)
Date: 01/30/04

  • Next message: Hong Ooi: "Re: [OT] The Deathstation"
    Date: Fri, 30 Jan 2004 12:29:59 -0200
    
    

    Is getopt() and its companions, commonly found in GNU libc and other
    Unices libc, part of the C standard?

    Another doubt: I have a switch inside a while loop; is there a way to
    break out of the loop from the switch without using goto? I mean:

    start:
    while(chr = fgetc(inputfile))
    {
     switch(chr)
    {
     case 'a': case 'b':
      do_one_stuff(chr);
      break;
     case 'c': case 'd':
      do_some_other_stuff(chr);
      break;
     case 'e': case 'f':
      do_stuff(chr);
      break;
     default:
       goto start;
    } /* end switch */
    do_even_more_stuff_here();
    } /* end while */

    Is there a way to get out of the while (i.e., skipping the
    "do_even_more_stuff_here();" part) without using this goto?

    Thank in advance.

    -- 
    Quidquid latine dictum sit altum viditur
    

  • Next message: Hong Ooi: "Re: [OT] The Deathstation"

    Relevant Pages

    • Re: acceptable use of goto?
      ... loop, forward within the loop at various points, then forward out of ... Then you give every statement a label. ... No goto statements. ... Then I build a framework (of if or switch statements) to eliminate the ...
      (comp.lang.c)
    • Re: How would you do this?
      ... But, as I've said before, I don't actually think that a "goto" statement is something to be avoided in and of itself. ... Interestingly, in Java there is no "goto" statement and the "break" and "continue" statements are specifically designed to allow for this kind of scenario. ... Similarly, the "continue" statement can continue a labeled loop block, rather than just the inner-most one. ... This forces the programmer to be explicit about falling through to the next switch, allowing the compiler to emit an error if they aren't. ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Is getopt() standard C? etc.
      ... but it is part of POSIX (which is OT in this newsgroup). ... > break out of the loop from the switch without using goto? ... say goto start which is the start of the while loop). ... just fine as it doesnt have special meaning inside the switch. ...
      (comp.lang.c)
    • Re: a goto command???
      ... I treat goto like I treat eval in MATLAB. ... This saves a comparison operation on each loop iteration. ... which uses the switch technique outlined above but wrapped in macros to implement a lightweight stackless threading model. ...
      (comp.soft-sys.matlab)
    • Re: break inside of case- statement inside of loop
      ... Is it possible to break out of the for loop from inside of one case- ... break only gets you out of the smallest enclosing switch or loop. ... Or you could use goto: ... -Beej--4am...hopefully I didn't screw that answer up too bad. ...
      (comp.lang.c)