• Re: labels at the end of a function

    From Peter Klausler US@21:1/5 to Lynn McGuire on Mon Aug 29 18:58:41 2022
    On Monday, August 29, 2022 at 6:35:54 PM UTC-7, Lynn McGuire wrote:
    I just found out that a label at the end of a c/c++ function must have
    an executable statement after it.

    int aMethod ()
    {
    int aFakeVar = 0;

    goto aLabel;

    aLabel:

    aFakeVar++;
    }

    Is there any way to get around the requirement of the executable
    statement after the label ?

    Thanks,
    Lynn

    Use an empty statement, i.e. "label:;".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lynn McGuire@21:1/5 to Peter Klausler US on Mon Aug 29 21:01:39 2022
    On 8/29/2022 8:58 PM, Peter Klausler US wrote:
    On Monday, August 29, 2022 at 6:35:54 PM UTC-7, Lynn McGuire wrote:
    I just found out that a label at the end of a c/c++ function must have
    an executable statement after it.

    int aMethod ()
    {
    int aFakeVar = 0;

    goto aLabel;

    aLabel:

    aFakeVar++;
    }

    Is there any way to get around the requirement of the executable
    statement after the label ?

    Thanks,
    Lynn

    Use an empty statement, i.e. "label:;".

    Thanks for the advice. Sorry, I only meant to post to the C and C++ groups.

    Lynn

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lynn McGuire@21:1/5 to All on Mon Aug 29 20:35:50 2022
    XPost: comp.lang.c, comp.lang.c++

    I just found out that a label at the end of a c/c++ function must have
    an executable statement after it.

    int aMethod ()
    {
    int aFakeVar = 0;

    goto aLabel;

    aLabel:

    aFakeVar++;
    }

    Is there any way to get around the requirement of the executable
    statement after the label ?

    Thanks,
    Lynn

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Peter Klausler US on Mon Aug 29 22:25:56 2022
    On Monday, August 29, 2022 at 6:58:43 PM UTC-7, Peter Klausler US wrote:

    (snip)

    Is there any way to get around the requirement of the executable
    statement after the label ?

    Use an empty statement, i.e. "label:;".

    It is called a null statement, but otherwise yes, it should work.

    Since the function returns int, you will get a warning about no return statement.

    You could put the return 0; or some other value, there.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bo Persson@21:1/5 to Lynn McGuire on Tue Aug 30 09:14:49 2022
    XPost: comp.lang.c, comp.lang.c++

    On 2022-08-30 at 03:35, Lynn McGuire wrote:
    I just found out that a label at the end of a c/c++ function must have
    an executable statement after it.

    int aMethod ()
    {
        int aFakeVar = 0;

        goto aLabel;

        aLabel:

        aFakeVar++;
    }

    Is there any way to get around the requirement of the executable
    statement after the label ?


    Not right now, but it will be allowed in C++23. :-)

    https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2324r2.pdf

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Lynn McGuire on Tue Aug 30 13:21:09 2022
    XPost: comp.lang.c, comp.lang.c++

    Lynn McGuire <lynnmcguire5@gmail.com> writes:
    I just found out that a label at the end of a c/c++ function must have
    an executable statement after it.

    int aMethod ()
    {
    int aFakeVar = 0;

    goto aLabel;

    aLabel:

    aFakeVar++;
    }

    Is there any way to get around the requirement of the executable
    statement after the label ?

    Your function is missing a return statement.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Kenny McCormack on Tue Aug 30 12:11:57 2022
    On Tuesday, August 30, 2022 at 7:44:23 AM UTC-7, Kenny McCormack wrote:

    (snip)

    P.S. Why is this also posted to a Fortran group?

    I believe it was accidental, but since you could call it
    with the C interoperability feature, it might be applicable.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Thomas Koenig on Tue Aug 30 14:39:14 2022
    On Tuesday, August 30, 2022 at 2:24:18 PM UTC-7, Thomas Koenig wrote:

    (snip)

    Fortran has no problem with labels at the end of subroutines
    or functions. This is legal:

    subroutine a
    goto 100
    100 end subroutine a

    although good style would seem to advise

    subroutine a
    goto 100
    100 continue
    end subroutine a

    (The "continue" statement is a do-nothing placeholder).

    It didn't always do that.

    In Fortran 66, and I believe 77, END is a non-executable statement.
    You are supposed to have STOP or RETURN (or GOTO) before it.

    I suspect many allowed one to skip the STOP or RETURN, but
    still no label on END.

    In any case, the C function with type other than void should have a
    return with appropriate type. Compilers will usually give warning
    or error if you don't. And then you can label the return.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to gah4@u.washington.edu on Tue Aug 30 21:24:14 2022
    gah4 <gah4@u.washington.edu> schrieb:
    On Tuesday, August 30, 2022 at 7:44:23 AM UTC-7, Kenny McCormack wrote:

    (snip)

    P.S. Why is this also posted to a Fortran group?

    I believe it was accidental, but since you could call it
    with the C interoperability feature, it might be applicable.

    Fortran has no problem with labels at the end of subroutines
    or functions. This is legal:

    subroutine a
    goto 100
    100 end subroutine a

    although good style would seem to advise

    subroutine a
    goto 100
    100 continue
    end subroutine a

    (The "continue" statement is a do-nothing placeholder).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Shepelev@21:1/5 to All on Wed Aug 31 01:04:25 2022
    XPost: comp.lang.c, comp.lang.c++

    Lynn McGuire to Kenny McCormack:

    P.S. Why is this also posted to a Fortran group?

    Because I typed comp.lang.c into Thunderbird and
    Thunderbird graciously also put comp.lang.fortran in there
    for me which I did not notice.

    Amazing grace. Did you mean `gratuitiously'?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)