Results 1 to 2 of 2

Thread: What's it with this kind of definition?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    21

    What's it with this kind of definition?

    Some places till now, I've seen function prototypes within functions instead of in the global declaration space, which I thought was the way.

    I thought it was only:

    Code:
    int myfunction(int, int);
    
    int main(void)
    {
        int a,b;
        return myfunction(a,b);
    }
    But I've also seen:

    Code:
    int main(void)
    {
        int a, b, myfunction(int, int);
        return myfunction(a,b);
    }
    I've seen this in K&R as well, but haven't come accross a piece that talks about this kinda declaration.
    What's the deal here? I understand it as follows:

    It defines the scope of usage. If defined in the global space, much like extern variables, the function can be called from anywhere within the file. If declared within another function, it may be called only from within that function in which it is defined.

    How true?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Never seen that actually used, although I know it's legal. I don't think it's a good idea though.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width