• Where are return codes documented?

    From Peter Percival@21:1/5 to All on Mon Sep 5 12:02:08 2016
    Where are return codes documented? Specifically, what does Return code
    53 signify?
    --
    Do, as a concession to my poor wits, Lord Darlington, just explain
    to me what you really mean.
    I think I had better not, Duchess. Nowadays to be intelligible is
    to be found out. -- Oscar Wilde, Lady Windermere's Fan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jacobnavia@21:1/5 to All on Mon Sep 5 13:27:31 2016
    Le 05/09/2016 à 13:02, Peter Percival a écrit :
    Where are return codes documented? Specifically, what does Return code
    53 signify?

    return codes of WHAT?

    Of some windows API?
    From lcc?
    fropm lcclnk?

    Please specify

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jacobnavia@21:1/5 to All on Tue Sep 6 11:38:42 2016
    Le 06/09/2016 à 11:19, Peter Percival a écrit :

    So my question is, why 53? Why anything, though 0 would be less
    surprising.

    #include <stdio.h>

    void main()
    {
    double f = 1.0;

    union {double uf; char c[8];} u;

    printf("Size of double = %d\n", sizeof(double));

    u.uf = f;
    printf("Double = %f, bytes = %d, %d, %d, %d, %d, %d, %d, %d\n", u.uf,
    u.c[0], u.c[1], u.c[2], u.c[3], u.c[4], u.c[5], u.c[6], u.c[7]);

    }

    You never assign a return value to main(). The return value is then
    whatever was in the register EAX when you return from that function.

    Since all functions return their result in the eax register, the last
    function to be called was printf, that returns 53 since it wrote 53
    chars to standard output.

    That value is left in that register at main's exit and is assumed to be
    the result of main().

    That is why 53.

    mean, if you do not assign a result to a function the return value can
    be ANYTHING

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Percival@21:1/5 to jacobnavia on Tue Sep 6 10:19:05 2016
    jacobnavia wrote:
    Le 05/09/2016 à 13:02, Peter Percival a écrit :
    Where are return codes documented? Specifically, what does Return code
    53 signify?

    return codes of WHAT?

    Of some windows API?
    From lcc?
    fropm lcclnk?

    Please specify

    Oh, sorry, you're right I was a bit vague! I'm refering to a console
    program. The program seems to run correctly. The name of the
    executable between double quote marks is displayed, and then

    Return code 53

    is displayed. The program is short enough to be reproduced in its
    entirety, so I do so below. It is my belief that if I had declared main
    to return an int, and if I had ended it with a statement

    return 88;

    say, then I would see

    Return code 88.

    So my question is, why 53? Why anything, though 0 would be less surprising.

    #include <stdio.h>

    void main()
    {
    double f = 1.0;

    union {double uf; char c[8];} u;

    printf("Size of double = %d\n", sizeof(double));

    u.uf = f;
    printf("Double = %f, bytes = %d, %d, %d, %d, %d, %d, %d, %d\n", u.uf,
    u.c[0], u.c[1], u.c[2], u.c[3], u.c[4], u.c[5], u.c[6], u.c[7]);

    }


    --
    Do, as a concession to my poor wits, Lord Darlington, just explain
    to me what you really mean.
    I think I had better not, Duchess. Nowadays to be intelligible is
    to be found out. -- Oscar Wilde, Lady Windermere's Fan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From BartC@21:1/5 to jacobnavia on Tue Sep 6 11:30:28 2016
    On 06/09/2016 10:38, jacobnavia wrote:
    Le 06/09/2016 à 11:19, Peter Percival a écrit :

    So my question is, why 53? Why anything, though 0 would be less
    surprising.

    #include <stdio.h>

    void main()
    {

    }

    You never assign a return value to main(). The return value is then
    whatever was in the register EAX when you return from that function.

    Since all functions return their result in the eax register, the last function to be called was printf, that returns 53 since it wrote 53
    chars to standard output.

    I don't think that's right. If I execute this:

    int main(void) {
    static int first=1;
    if (first) {
    first=0;
    printf("Main returns: %d\n",main());
    }
    }

    most compilers make main() return 0. Including lccwin (looking at the
    generated code, it actually loads 0 into eax!).

    Of course the OP's example uses 'void main' not 'int main', which might
    be a bit different.

    So perhaps just making that change is all that's needed to get a more
    reliable return value.

    --
    bartc

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Peter Percival on Tue Sep 6 10:38:10 2016
    Peter Percival <peterxpercival@hotmail.com> writes:
    jacobnavia wrote:
    Le 05/09/2016 à 13:02, Peter Percival a écrit :
    Where are return codes documented? Specifically, what does Return code
    53 signify?

    return codes of WHAT?

    Of some windows API?
    From lcc?
    fropm lcclnk?

    Please specify

    Oh, sorry, you're right I was a bit vague! I'm refering to a console program. The program seems to run correctly. The name of the
    executable between double quote marks is displayed, and then

    Return code 53

    is displayed. The program is short enough to be reproduced in its
    entirety, so I do so below. It is my belief that if I had declared main
    to return an int, and if I had ended it with a statement

    return 88;

    say, then I would see

    Return code 88.

    I'm curious just what is displaying the message "Return code 53". That
    depends on the environment in which you're running the program.

    So my question is, why 53? Why anything, though 0 would be less surprising.

    #include <stdio.h>

    void main()
    {
    double f = 1.0;

    union {double uf; char c[8];} u;

    printf("Size of double = %d\n", sizeof(double));

    u.uf = f;
    printf("Double = %f, bytes = %d, %d, %d, %d, %d, %d, %d, %d\n", u.uf,
    u.c[0], u.c[1], u.c[2], u.c[3], u.c[4], u.c[5], u.c[6], u.c[7]);

    }

    A correct definition of "main" is `int main(void)`, not `void main()`.
    If it takes command-line arguments, use
    int main(int argc, char *argv[])
    or equivalent. Some compilers do support `void main()` (and the
    standard does permit them to do so), but there's really no good reason
    to use it. If your compiler doesn't say that it supports `void main()`,
    then your program's behavior is undefined -- and the compiler is not
    required to complain about it.

    As of C90, if you correctly define main as `int main(void)` and you
    don't explicitly return a value, then the status returned to the calling environment is undefined; 53 is as valid and as likely as anything else.
    (It's probably the value returned by the printf() call, left in some
    register that's also used to return a value from main. printf() returns
    the number of characters it printed, which just happens to be 53 in this
    case.)

    As of C99 or later, falling off the end of main() does an implicit
    `return 0;`. If you're not sure whether your compiler supports one of
    the later standards, add an explicit `return 0;` at the end.

    Also, the "%d" format requires an argument of type int, but
    `sizeof(double)` is of type size_t. It might happen to work
    correctly, but don't count on it. The correct format for size_t is
    "%zu" -- but that was introduced in C99. If you're not sure whether
    your implementation supports "%zu", you can convert the size_t value
    to some known type. The safest type to use here is unsigned long,
    so you can change your first printf call to:

    printf("Size of double = %lu\n", (unsigned long)sizeof(double));

    --
    Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Working, but not speaking, for JetHead Development, Inc.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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