Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion __FUNCTION__ ????

View Parsed - Show only message text

Message-ID: <3BD01882.BE2CDBC0@amsjv.com>
Date: Fri, 19 Oct 2001 13:11:46 +0100
From: Des Walker <des.wal...@amsjv.com>
Organization: Alenia-Marconi Systems
X-Mailer: Mozilla 4.61 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.lang.c
Subject: Re: __FUNCTION__ ????
References: <47295485.0110190255.7f389085@posting.google.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: farwkn6911.frlngtn.gecm.com
X-Trace: 19 Oct 2001 13:00:17 GMT, farwkn6911.frlngtn.gecm.com
Lines: 81
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!btnet-peer1!btnet-feed5!btnet!newreader.ukcore.bt.net!pull.gecm.com!farwkn6911.frlngtn.gecm.com

Sobhan Vezzu wrote:
> 
> Hello All,
> 
>          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;
> }
> int main()
> {
>         char info[50];
>         FILE *fp;
> 
>         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;
> }
> 
> bye,
> Sobhan

Hi,

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.

	Regards
	Des Walker

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google