Mail Archives: djgpp/1996/09/07/21:02:40
On Wednesday, in article <50k7f2$c9f AT epx DOT cis DOT umn DOT edu>
hoffo002 AT gold DOT tc DOT umn DOT edu "Jason Hoffoss" wrote:
> Hmm, my thoughts on this has always been that main can be declared
> several ways, depending on your needs. If you don't use command line
> arguments, you can declare it as taking none, and if you don't need to
> return an error code when your program exits, you can declare the
> return type void.
That is a bad comparison. In C, a function (itself, not the code) can
completely ignore the arguments if it wants, as the calling function will
clean up the stack. Hence declaring with no args will break nothing.
However, whatever a function returns affects the calling function.
This is why C has variable length and type argumeent lists, but *not*
variable type returns.
> Thus, for most simple programs (which is usually
> what you learn in introductory courses), you'll use..
>
> void main()
And how is this easier than:
main()
?
> However, for a big complex program, you'll generally use this instead:
>
> int main(int argc, char *argv[] )
You mean one that uses arguments. I have a very small and simple program
which has that.
> There isn't any one required way to declare main(). It just depends
> on your needs. Of course, almost all sources that teach you
> programming always assume simple cases for everything, which doesn't
> do anything to prepare you for the 'real stuff' you get into later,
> which you have to basically tackle on your own. That's probably the
> biggest flaw with courses.
OK, then I want my program to return struct foo, and I want the command line
in one long string.
struct foo main(char *cmdline);
Do you think this will work?
..splitbung http://www.tsys.demon.co.uk
--
A great many people think they are thinking when they are merely
rearranging their prejudices. -- William James
[unknown]
- Raw text -