CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    8

    In c , how come function may have several declarations but only one definition?

    In c , how come function may have several declarations but only one definition? Can someone elaborate on that plz

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: In c , how come function may have several declarations but only one definition?

    Can you define "several declarations"? As far as I know, in both C and C++ functions can have only one declaration and definition.

    Viggy

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: In c , how come function may have several declarations but only one definition?

    A declaration says "Such a thing exists." It doesn't matter how many times you say this, so long as you're consistent about the interface. (C++ doesn't even require that, since it allows function overloading.)

    A definition says "This is what it is." If you say that multiple times, the linker will shrug in confusion about which one is really what it is.

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: In c , how come function may have several declarations but only one definition?

    Okay, if you look at the question that way, yes.

    I read the OP's question, and thought of overloaded functions, who's declarations are not the same (even if the function name is).

    Viggy

Tags for this Thread

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

Featured