> ----------
> From: Josh Muckley[SMTP:[EMAIL PROTECTED]]
> Reply To: Josh Muckley
> Sent: 9. september 1998 06:35
> To: Linux C Programming List; James
> Subject: Re: main()
>
>
> I believe that choice "A" is correct.
>
No, A is not "correct".
C was from the start designed with efficiency in mind, this goes for the
compilation as well as for the generated code. For this reason, the
language is designed to be compilable with a single pass compiler.
In a single pass, the compiler has no way of knowing symbols not
encountered yet. When in main() encountering calls to foo(), the latter
will in principle be undefined. Now traditional C will implicitly
declare such references as "int foo(<whatever called with>)"; due to the
C calling convention, the resulting binary may actually work. Typically
the compiler will later object to a "redefinition (declaration?) of
function with different parameter list" or something like that, though.
gcc warns at implicit declarations and the practice is considered
harmful, as any checking of calling functions with a correct parameter
list is impossible.
If you want a pascallish structure of C programs, use function
prototypes:
---snippet start---
int dothisandthat( int numberofcows, char * cownames[] );
int main()
{
...
int a = dothisandthat( 4711, mycownames );
...
}
int dothisandthat( int numberofcows, char * cownames[] )
{
<code goes here>
}
---snippet ends---
I believe there exists a tool "protoize" to automagically generate such
prototypes (and "unprotoize" to remove them again), but I have never
tried it.
regards,
Niels HP
[EMAIL PROTECTED]
> Josh
>
>
> ---James <[EMAIL PROTECTED]> wrote:
> >
> > where is the right place to put main()? before or after my function
> > definitions? Because i used to write Pascal code, i stick main()
> last
> > (in Pascal, the main begin..end pair must be the last function in
> the program).
> > does it matter? seems more logical to define your prototypes, write
> them,
> > then the main program.
> >
> > A:
> > /********/
> >
> > int main (){}
> >
> > int foo(){}
> >
> > int bar(){}
> > /*********/
> >
> > B:
> > /**********/
> > int foo()
> > {
> > }
> >
> > int bar(){}
> >
> > int main(){}
> > /**********/
> > --
> > +++ Divide By Cucumber Error, Please Re-Install Universe And Reboot
> +++
> > [EMAIL PROTECTED]
> http://x-map.home.ml.org
> >
> >
>
>
>
> _________________________________________________________
> DO YOU YAHOO!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>