S
spinoza1111
It is true that given the deficiencies of C, a void main() could break
a poorly-written OS.
If the OS expects a C program to return something, it probably has a
"stack" and expects this stack to increase by one as a result of
calling an executable C module. It can then safely pop this value and
pass it to a shell procedure for treatment as the return code.
If the procedure is void main(), this pop operation will damage or
even destroy the stack and create problems in the OS. For example, it
might cause the module which calls executables to return not to its
caller, but its caller's caller, with all sorts of bad things
happening.
It's not enough to say that the OS should record the size of the stack
and check after control returns from the executable for a stack size
of s+1; for in the general case, we know not where the abstract OS
could store this value. We are not, in the general scientific case,
able to assume that the executable caller has state (memory), and it
would be really, really stupid for the OS to save the size in what is
often the ONLY memory resource available to such "local" variables,
eg., the stack itself:
// ***** Really stupid code *****
int cExecutableCall(int intArgCount, char **ptrArgValue)
{
int intOldStackSize = stackSize();
main(intArgCount, ptrArgValue);
intRC = pop();
if (intOldStackSize != stackSize() + 1) comeWrack();
..
..
..
]
If main() is void, the pop() in the above will destroy
intOldStackSize, and come, wrack.
But properly understood, the compilability without showstopper error
of void main() is a gross and easily repaired bug in the C programming
language. It is allowed to "talk to" the OS and through it to shell
procedures, but it may send a poison pill in the form of a void main()
"message" which would (for example), give a mere shell procedure
access to a secure value.
Obviously, had the C99 and C89 standards geeks been men, they would
have fixed this problem. They could simply have legislated that all C
programs intended to run hosted would in the absence of a valid main
be given one.
Such a standard would have mandated what seems to me a simple
transformation:
void main()
{
printf("Hello world, I am a bonehead\n");
}
to
int _main(int argc, char **argv)
{
main();
return 0;
}
void main()
{
printf("Hello world, I am a bonehead\n");
}
where _main (or some suitable transformation of the name of main())
gets control.
The OS runtime can not be assumed to have either the complete "tuple"
of function name, return type and parameter list of the main(), nor
memory in which to remember the stack's size before the call of the
executable, therefore void main() programs are a security threat. But
it appears to me at this point that the C99 and C89 geeks, who seem to
have been selected from a mob of unqualified volunteers, had no
mandate to change C and thereby discommode vendors, who'd pleased Wall
Street by laying off senior, competent people able to make the above
change.
For void main() was not forbid outright, nor was it decided that the
coding of the main() procedure's header be taken out of the grubby
hands of mere C programmers, and they be forced to code something like
main
{
printf("Hello world, I am a bonehead\n");
}
where the keyword "main" would always expand to "int main(int argc,
char **argv), or
main(intArgumentCount, ptrArgumentValue)
{
printf("Hello world, I am a class act and can spell real wurdz\n");
}
where I give the programmer ONLY the ability to name the parameters,
and nothing more.
This would have upset the only "real" men...the money boys.
Instead, it's more fun to trash personal reputations while Wall Street
gets richer, Goldman Sachs uses incomprehensible and insecure C code
to make a mess of our future, and British Petroleum uses
incomprehensible and insecure C code to reassure the people of
Louisiana that "everything is under control".
a poorly-written OS.
If the OS expects a C program to return something, it probably has a
"stack" and expects this stack to increase by one as a result of
calling an executable C module. It can then safely pop this value and
pass it to a shell procedure for treatment as the return code.
If the procedure is void main(), this pop operation will damage or
even destroy the stack and create problems in the OS. For example, it
might cause the module which calls executables to return not to its
caller, but its caller's caller, with all sorts of bad things
happening.
It's not enough to say that the OS should record the size of the stack
and check after control returns from the executable for a stack size
of s+1; for in the general case, we know not where the abstract OS
could store this value. We are not, in the general scientific case,
able to assume that the executable caller has state (memory), and it
would be really, really stupid for the OS to save the size in what is
often the ONLY memory resource available to such "local" variables,
eg., the stack itself:
// ***** Really stupid code *****
int cExecutableCall(int intArgCount, char **ptrArgValue)
{
int intOldStackSize = stackSize();
main(intArgCount, ptrArgValue);
intRC = pop();
if (intOldStackSize != stackSize() + 1) comeWrack();
..
..
..
]
If main() is void, the pop() in the above will destroy
intOldStackSize, and come, wrack.
But properly understood, the compilability without showstopper error
of void main() is a gross and easily repaired bug in the C programming
language. It is allowed to "talk to" the OS and through it to shell
procedures, but it may send a poison pill in the form of a void main()
"message" which would (for example), give a mere shell procedure
access to a secure value.
Obviously, had the C99 and C89 standards geeks been men, they would
have fixed this problem. They could simply have legislated that all C
programs intended to run hosted would in the absence of a valid main
be given one.
Such a standard would have mandated what seems to me a simple
transformation:
void main()
{
printf("Hello world, I am a bonehead\n");
}
to
int _main(int argc, char **argv)
{
main();
return 0;
}
void main()
{
printf("Hello world, I am a bonehead\n");
}
where _main (or some suitable transformation of the name of main())
gets control.
The OS runtime can not be assumed to have either the complete "tuple"
of function name, return type and parameter list of the main(), nor
memory in which to remember the stack's size before the call of the
executable, therefore void main() programs are a security threat. But
it appears to me at this point that the C99 and C89 geeks, who seem to
have been selected from a mob of unqualified volunteers, had no
mandate to change C and thereby discommode vendors, who'd pleased Wall
Street by laying off senior, competent people able to make the above
change.
For void main() was not forbid outright, nor was it decided that the
coding of the main() procedure's header be taken out of the grubby
hands of mere C programmers, and they be forced to code something like
main
{
printf("Hello world, I am a bonehead\n");
}
where the keyword "main" would always expand to "int main(int argc,
char **argv), or
main(intArgumentCount, ptrArgumentValue)
{
printf("Hello world, I am a class act and can spell real wurdz\n");
}
where I give the programmer ONLY the ability to name the parameters,
and nothing more.
This would have upset the only "real" men...the money boys.
Instead, it's more fun to trash personal reputations while Wall Street
gets richer, Goldman Sachs uses incomprehensible and insecure C code
to make a mess of our future, and British Petroleum uses
incomprehensible and insecure C code to reassure the people of
Louisiana that "everything is under control".