Re: Ahead of "main"?



Malcolm McLean wrote:

Some early versions of C had local functions, declared within the function
that called them. The idea never caught on, and it is now not possible to
declare functions within main.

I'm not sure /exactly/ what you're saying; but if I read you
properly, what you're saying is false.

To the best of my knowledge, no "early" versions of C had local
functions, that is, functions /defined/ inside other functions.
(I don't count BCPL as an early version of C.)

Again to the best of my knowledge, /all/ versions of C allow you
to /declare/ -- not define -- (external) functions inside functions.

Old C also had no prototypes.

Yes (where "Old" means "pre-Standard", for a useful value of "had").

So if you put functions in reverse order of
hierarchy, the compiler could do additional checking of arguments.

Whatever the order you used, the compiler "could" do such checking.
In practice it didn't: one used "lint".

Nowadays we should prototype all functions,

Not true if by "prototype" you mean "declare with a prototype"
rather than "define using typed-argument syntax".

so it doesn't matter where
main() is placed, though obviously it should be either the first or the
last function for readbility.

I'm not sure about that last: it's not /obvious/, even if it's
true.

--
Prototypical Hedgehog
Meaning precedes definition.

.



Relevant Pages

  • Re: Ahead of "main"?
    ... On Mon, 30 Apr 2007 06:00:41 GMT, Chris Dollin ... declare functions within main. ... I'm not sure /exactly/ what you're saying; ... the compiler "could" do such checking. ...
    (comp.lang.c)
  • Re: Error checking with execlp()
    ... |>> I'm not saying that it is incorrect to include it. ... is to quash a compiler warning, usually about a possibly uninitialized variable ... enough to know that no path could be followed that would not assigne it. ... was a way to assert to the compiler that a variable really has been assigned ...
    (comp.unix.programmer)
  • Re: [Lit.] Buffer overruns
    ... > don't even have to bother swapping out the compiler. ... It does not take an adversary to create a security hole, ... And those errors abound. ... That is a far cry from saying that it is secure and can be ...
    (sci.crypt)
  • Re: C# Nullable types
    ... string x = null; ... compiler that by using the language specific word called "null". ... so we are given a keyword to state our intentions as the ... I am saying that I don't want x to have any value and I am "ok" with that. ...
    (microsoft.public.dotnet.framework)
  • Re: Flexible arrays - v confused
    ... and that includes using a C++ compiler (which has stricter type ... Or are you saying that anything superfluous, ... posts, you've known my counter argument before this post. ...
    (comp.lang.c)