Calling an undeclared function is poor style in C (See this) and illegal in C++. So is passing arguments to a function using a declaration that doesn’t list argument types:
If we save the below program in a .c file and compile it, it works without any error. But, if we save the same in a .cpp file, it doesn’t compile.
1 #include <stdio.h> 2 3 void f(); /* Argument list is not mentioned */ 4 5 int main() 6 { 7 f(2); /* Poor style in C, invalid in C++*/ 8 getchar(); 9 return 0; 10 } 11 12 void f(int x) 13 { 14 printf("%d", x); 15 }
'c' parameter checking is not done at declaration but in 'c++' parameter checking is done at declaration
Source: http://www2.research.att.com/~bs/bs_faq.html#C-is-subset
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
转载请注明:http://www.cnblogs.com/iloveyouforever/
2013-11-27 12:11:06