Thread: Need help in functions

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    32

    Question Need help in functions

    What do you mean by signature of function?

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    A function signature is the "title" of the function that contains the return value, function name and parameter types, basically everything you need to correctly identify that function:

    e.g.

    int main(void) is a possible signature of main.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Never heard it called that. Perhaps 'prototype'.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A prototype is a declaration. The signature of a function refers to the syntax involved in declaring or definition a function, I believe.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    I've never heard that term, "signature". But anyway, here's some example signatures. The return type's in red, the title's in blue, and the arguments are in green.

    Code:
    int main(int argc, char *argv[])
    
    FILE *fopen(const char *restrict filename, const char *restrict mode)
    
    int sqrt(int x)

  6. #6
    Registered User
    Join Date
    Mar 2008
    Location
    Coimbra, Portugal
    Posts
    85
    I've heard the term signature when talking about calling conventions or when talking about the output of CRC32, checksum and other similar algorithms applied to the whole or portions of raw binary function code (used by some anti-cheat systems to detect changes in functions).

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by C++03 Clause 1.3.10
    signature
    the information about a function that participates in overload resolution: the types of its parameters and, if the function is a class member, the cv-qualifiers (if any) on the function itself and the class in which the member function is declared. (Note 2) The signature of a function template specialization includes the types of its template arguments.

    Note 2) Function signatures do not include return type, because that does not participate in overload resolution.
    As far as I can tell, the 1999 edition of the C standard does not even contain the word "signature", and my guess for this is that this is because C does not have function overloading, so it would suffice to talk about a function type or a function declaration.
    Last edited by laserlight; 09-21-2010 at 12:41 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by laserlight View Post
    As far as I can tell, the 1999 edition of the C standard does not even contain the word "signature",
    Well it probably does... down at the bottom where the committee signed their names...

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    For C++, the return type isn't part of the signature, since you can't overload a function by only changing its return type.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  10. #10
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    As far as I know signature is a generic term and is non specific to a particular language. It's true that signatures are particularly relevant for overloading, but the term is not strictly related to languages that allow overloading.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of functions
    By frktons in forum C Programming
    Replies: 29
    Last Post: 06-30-2010, 09:51 AM
  2. Need help with functions
    By jusfry01 in forum C Programming
    Replies: 2
    Last Post: 05-22-2010, 06:25 PM
  3. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  4. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  5. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM