| |
comp.lang.c |
I understood that __FUNCTION__ is a preprocessor macro, which
will substitute a file name. Similar to __FILE__ and __LINE__.
1) I have written a small code, only for __FUNCTION__ it
prints as unknown why? What is the difference between __FILE__ and
__FUNCTION__. When I comment #ifndef __FUNCTION block it prints the
file name.
2) Where do I get a list of all the preprocessor macros.
#include <stdio.h>
#include <errno.h>
#ifndef __LINE__
#define __LINE__ 0
#endif
#ifndef __FILE__
#define __FILE__ "Unknown"
#endif
#ifndef __FUNCTION__
#define __FUNCTION__ "Unknown"
#endif
int assert(int bool, int line, char *file, char *fun)
{
char mesg[100];
sprintf(mesg, "line: %d, file: %s, function: %s\nError ", line, file,
fun);
if(bool){
perror(mesg);
errno = 0;
}
return 1;
errno = 0;
fp = fopen("ex.dat", "r");
assert(fp == NULL, __LINE__ - 1, __FILE__, __FUNCTION__);
fp = fopen("t.c", "r");
assert(errno != 0, __LINE__, __FILE__, __FUNCTION__);
return 1;