Learn C Function by Example 3 : Name of function cannot be global predefined macro

December 20, 2024 No Comments » Hits : 65






Basic Note :

  • Global predefined macro starts with underscore. (_) .
  • We cannot use Global predefined macro as our function name.

Example : Some of the predefined macros in C

  • __TIME__
  • __DATE__
  • __FILE__
  • __LINE__

Learn by Program : Valid Example

#include<stdio.h>
void __FILE__();
int main()
{
   __FILE__();
}
void __FILE__(){
   printf("Hello World");
}

Output :

Compile error

We can have valid function names starting with underscore -

  • _add()
  • _getTime()
  • _calsum()

Note :

Try to avoid using underscore as first character .

Why we should avoid to use underscore as first character ?

  • Using underscore as first character is perfectly legal in C.
  • But in C we have many more different predefined constants and macros starting with underscore.
  • It will create confusion between user defined and predefined identifier.
  • so prefer not to use underscore as first character in writing function.

You may like these articles :