Be careful of Magic behaviour due to compilers

This tip submitted by manik on 2011-10-14 07:11:41. It has been viewed 10409 times.
Rating of 6.1 with 48 votes



Always try to define functions before using it or at least give prototype.

Else some compilers like gcc will cause different behaviour

#include 
int main()
{
  fun(); // calling with empty param
  return 0;
}
void fun(int a) 
{
  a=10;
  printf("a=%d\n",a);
}


If you compile this code using gcc, you will get surprised because it will allow the function call. So avoid using functions before they are declared.



More tips

Help your fellow programmers! Add a tip!