Learn C Function by Example 3 : Name of function cannot be global predefined macro
Basic Note :
[arrowlist]
- Global predefined macro starts with underscore. (_) .
- We cannot use Global predefined macro as our function name.
Example : Some of the predefined macros in C
[crosslist]
- __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 -
[checklist]
- _add()
- _getTime()
- _calsum()
Try to avoid using underscore as first character .
Why we should avoid to use underscore as first character ?
[arrowlist]
- 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.