View Single Post
Old Oct 7th, 2006, 8:28 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Note that in this program the sum function is used before it is defined. It is also not pre-declared or prototyped. The compiler issues this warning:
Quote:
Compiling...
undeclared.c
C:\Documents and Settings\David\My Documents\My Windows\undeclared\undeclared.c(5) : warning C4013: 'sum' undefined; assuming extern returning int

undeclared.obj - 0 error(s), 1 warning(s)
#include <stdio.h>

int main (int argc, char * argv [])
{
    printf ("Sum of 2 and 2 is %d\n", sum (2, 2));
}

int sum (int a, int b)
{
    return a+b;
}
Note from the output that the function performs as written. You cannot do this in C++. There are a number of reasons that C++ is NOT a superset of C, though it seems to be the case for many things. My son has a goodly number of my genes. He is not a superset, though he is both larger and meaner.
Quote:
Originally Posted by Output
Sum of 2 and 2 is 4
Press any key to continue
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote