| |
comp.lang.c |
> Hello All, > I understood that __FUNCTION__ is a preprocessor macro, which > 1) I have written a small code, only for __FUNCTION__ it > #include <stdio.h> > #ifndef __LINE__ > #ifndef __FILE__ > #ifndef __FUNCTION__ > int assert(int bool, int line, char *file, char *fun) > errno = 0; > fp = fopen("t.c", "r"); > bye, C99 introduced the identifier __func__ to provide the function name as a __func__ is not a preprocessor macro like __FILE__ and __LINE__, but an To get a list of current macro definitions, you could do a google search Or you could have a look at Stan Browns' compilation of 'Identifiers not Regards
> will substitute a file name. Similar to __FILE__ and __LINE__.
> 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 <errno.h>
> #define __LINE__ 0
> #endif
> #define __FILE__ "Unknown"
> #endif
> #define __FUNCTION__ "Unknown"
> #endif
> {
> char mesg[100];
> sprintf(mesg, "line: %d, file: %s, function: %s\nError ", line, file,
> fun);
> if(bool){
> perror(mesg);
> errno = 0;
> }
> return 1;
> }
> int main()
> {
> char info[50];
> FILE *fp;
> fp = fopen("ex.dat", "r");
> assert(fp == NULL, __LINE__ - 1, __FILE__, __FUNCTION__);
> assert(errno != 0, __LINE__, __FILE__, __FUNCTION__);
> return 1;
> }
> Sobhan
string. __FUNCTION__ would have to be implementation specific and you'll
need to ask in a newsgroup for your compiler.
identifier for the function in which it is used. It doesn't have any
meaning outside of a function body. If your compilers use of
__FUNCTION__ is similar this might be why your (re)definition occurs.
Note in C99 defining __func__ yourself results in undefined behaviour.
for "N869", which is a copy of the committee draft for the C99 spec. It
differs slightly from the final C99 spec, but it is free. (You can
purchase a copy of the C99 spec from http://www.ansi.org )
to use in C programs'
http://www.oakroadsystems.com/tech/c-predef.htm
It doesn't cover C99, but does allow you to pause for thought if you're
writing portable C code.
Des Walker