Peter Percival <
[email protected]> 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)
[email protected] <
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)