about goto

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abubakar

    #1

    about goto

    Hi,
    I got this code from some site:

    #include <stdio.h>
    int
    main() {
    int n = -1;
    x0:
    printf("%d\n" , ++n);
    goto *(&&x0 + n/1000 * (&&x1 - &&x0));
    x1:
    return 0;
    }

    it doesnt compile successfully. Apparently the goto statement need a
    hardcoded *label* for a correct compilation. The above code maybe written in
    gcc i think. Am i right to say that this code cannot compile in vc?

    regards,
    ...ab


  • Ben Voigt [C++ MVP]

    #2
    Re: about goto


    "Abubakar" <q@y.comwrote in message
    news:eOeg3w1fIH A.320@TK2MSFTNG P02.phx.gbl...
    Hi,
    I got this code from some site:
    >
    #include <stdio.h>
    int
    main() {
    int n = -1;
    x0:
    printf("%d\n" , ++n);
    goto *(&&x0 + n/1000 * (&&x1 - &&x0));
    x1:
    return 0;
    }
    >
    it doesnt compile successfully. Apparently the goto statement need a
    hardcoded *label* for a correct compilation. The above code maybe written
    in gcc i think. Am i right to say that this code cannot compile in vc?
    Neither C nor C++ allow computed goto. Computed goto may have some
    performance advantages over naive control structures, but the optimizing
    compiler should generate code at least as fast as computed goto.
    >
    regards,
    ..ab
    >

    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: about goto


      "Ben Voigt [C++ MVP]" <rbv@nospam.nos pamwrote in message
      news:%234OdQc8f IHA.5900@TK2MSF TNGP02.phx.gbl. ..
      >
      "Abubakar" <q@y.comwrote in message
      news:eOeg3w1fIH A.320@TK2MSFTNG P02.phx.gbl...
      >Hi,
      >I got this code from some site:
      >>
      >#include <stdio.h>
      >int
      >main() {
      > int n = -1;
      >x0:
      > printf("%d\n" , ++n);
      > goto *(&&x0 + n/1000 * (&&x1 - &&x0));
      >x1:
      > return 0;
      >}
      >>
      >it doesnt compile successfully. Apparently the goto statement need a
      >hardcoded *label* for a correct compilation. The above code maybe written
      >in gcc i think. Am i right to say that this code cannot compile in vc?
      >
      Neither C nor C++ allow computed goto. Computed goto may have some
      performance advantages over naive control structures, but the optimizing
      compiler should generate code at least as fast as computed goto.
      Also note that an array of function pointers is possible in C (or C++), and
      provides a computed gosub.
      >
      >>
      >regards,
      >..ab
      >>
      >
      >

      Comment

      Working...