"no previous prototype for function 'addition'" it doesn't stop the program from running successfully, but i just want to know what it means for future reference.
#include <iostream>
usingnamespace std;
int addition (int o,int t)
{
int s;
s = o+t;
return (s);
}
int main (int argc, constchar * argv[])
{
int twonumbers;
int onenumber;
cout << "enter a number";
cin >> onenumber;
cout << "and another";
cin >> twonumbers;
cout << "and now...";
sleep(1);
cout << "the sum of those two numbers is" << addition(onenumber,twonumbers);
return 0;
}
A function prototype allows you to declare that a function exists without actually giving it a body. For example... this would be a prototype for your addition function:
1 2
int addition (int o,int t); // <- note the semicolon
// <- and no {braces} or body
To eliminate the warning you could put the prototype before the function definition. Though it's really unnecessary.
Personally... I would ignore the warning and even consider tweaking build options to lower the warning level. That warning is pretty absurd, IMO.
Warnings are (or should be) for detecting potential logical problems in code that may compile but might not do what the developer intended.
The worst thing that can happen if you don't prototype a function is you'll try to call it and it won't be declared. In which case you'll get a compiler error telling you.
I cannot imagine any situation where this would manifest into a runtime bug. Therefore issuing a compiler warning literally has no value.
So yeah... completely absurd. Only sense I can make of it is someone was trying to push some kind of coding standard on the user ("all functions must have prototypes!!!")
-Wmissing-prototypes (C and Objective-C only)
Warn if a global function is defined without a previous prototype declaration.
This warning is issued even if the definition itself provides a prototype. Use
this option to detect global functions that do not have a matching prototype
declaration in a header file. This option is not valid for C++ because all
function declarations provide prototypes and a non-matching declaration will
declare an overload rather than conflict with an earlier declaration. Use
-Wmissing-declarations to detect missing declarations in C++.
Edit: The example is plain bad
Having void foo(bool); would make the warning go away.