Thread: Function Prototype Doubt

  1. #1
    Registered User
    Join Date
    Apr 2010

    Arrow Function Prototype Doubt

    A quick simple question...

    I've read at somewhere that function prototypes are not compulsory in C n are in C++ .
    But i tried a program without a function prototype n yeah i got errors..


  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    So either (1) you were compiling in C++ (2) you did something else that caused an error (3) you got a warning about it and thought it was an error (4) some combination of the above.

    (EDIT: Also, if you don't have a prototype in scope, there are certain assumptions that are made -- the return type of the function is int, some integral types (like char or short) are promoted to int, etc. If those aren't true, then you introduce a contradiction between the assumption and what reality turns out to be.)

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    In some perspectives, warnings are considered "bad". To that end, I would recommend that one always protos one's functions for sake of having no output during a build.

    In my current company, warnings are allowed, however, are considered (by some) to be buggy code.

  4. #4
    Registered User
    Join Date
    Apr 2010
    The Netherlands
    tabstop probably got the point over there... Probably, you defined the function after you used the function somewhere in the code before it. This way, the compiler will use an implicit declaration. That is, it makes a prototype itself with some standard values. I think it's something like
    int bogusfunction();
    If you then declare the real function later, using a different return type, or different arguments, the compiler will give you an error, telling you the function was declared twice, with unmatching parameters. Which is BAD.

    You probably do want to include some function prototypes at the top of your source file, or write a header file, containing all function prototypes. That way, you always have a prototype declared, and you will never get any errors

  5. #5
    Registered User
    Join Date
    Apr 2010
    ok so i had defined a function with return type void. that gave an error..

    now i tried a function with return type int. got just a warning.

    so it is that the compiler provides an implicit prototype with return type int only.

    k..thanks all..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. call to function without prototype
    By lgbeeb in forum C Programming
    Replies: 2
    Last Post: 03-25-2003, 12:20 PM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM