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.
> 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.
C99 introduced the identifier __func__ to provide the function name as a string. __FUNCTION__ would have to be implementation specific and you'll need to ask in a newsgroup for your compiler.
__func__ is not a preprocessor macro like __FILE__ and __LINE__, but an 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.
To get a list of current macro definitions, you could do a google search 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 )
Or you could have a look at Stan Browns' compilation of 'Identifiers not 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.
sob...@eudoramail.com (Sobhan Vezzu) writes: > I understood that __FUNCTION__ is a preprocessor macro, which > will substitute a file name. Similar to __FILE__ and __LINE__.
__FUNCTION__ is a GCC-specific extension. Please read the node "Function Names" in the GCC Info file or "Function Names as Strings" in the printed manual; it's all explained there.
> 1) I have written a small code, only for __FUNCTION__ it > prints as unknown why?
__FUNCTION__ is not a preprocessor macro, because the preprocessor does not know about functions.
C99 has a similar identifier __func__, which isn't a preprocessor macro either.
> 2) Where do I get a list of all the preprocessor macros.
If you're using GCC on Unix, you can do this:
gcc -E -dM -xc /dev/null
i.e., preprocess an empty file as C and list all defined macros when finished. Many of those macros are not in any standard.
In article <47295485.0110190255.7f389...@posting.google.com> sob...@eudoramail.com "Sobhan Vezzu" writes:
>Hello All,
> I understood that __FUNCTION__ is a preprocessor macro, which >will substitute a file name. Similar to __FILE__ and __LINE__.
The C language doesn't define anything called __FUNCTION__ although it does define __FILE__ and __LINE__
> 1) I have written a small code, only for __FUNCTION__ it >prints as unknown why?
Perhaps because it isn't defined?
>What is the difference between __FILE__ and >__FUNCTION__. When I comment #ifndef __FUNCTION block it prints the >file name.
You compiler may provide __FUNCTION__ as an extension. Most likely it will expand to the name of the function containing it. If it isn't in a function then it won't be able to expand to anything. The new C standard C99 does introduce something like this but it is called __func__ and it is *not* a macro, it acts like the name of a static variable within that function.
> 2) Where do I get a list of all the preprocessor macros.
-- Chuck F (cbfalco...@yahoo.com) (cbfalco...@XXXXworldnet.att.net) Available for consulting/temporary embedded and systems. (Remove "XXXX" from reply address. yahoo works unmodified) mailto:u...@ftc.gov (for spambots to harvest)