Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
__FUNCTION__ ????
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Sobhan Vezzu  
View profile   Translate to Translated (View Original)
 More options 19 Oct 2001, 11:55
Newsgroups: comp.lang.c
From: sob...@eudoramail.com (Sobhan Vezzu)
Date: 19 Oct 2001 03:55:05 -0700
Local: Fri 19 Oct 2001 11:55
Subject: __FUNCTION__ ????
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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Des Walker  
View profile   Translate to Translated (View Original)
 More options 19 Oct 2001, 13:13
Newsgroups: comp.lang.c
From: Des Walker <des.wal...@amsjv.com>
Date: Fri, 19 Oct 2001 13:11:46 +0100
Local: Fri 19 Oct 2001 13:11
Subject: Re: __FUNCTION__ ????

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kalle Olavi Niemitalo  
View profile   Translate to Translated (View Original)
 More options 19 Oct 2001, 13:16
Newsgroups: comp.lang.c
From: Kalle Olavi Niemitalo <k...@iki.fi>
Date: 19 Oct 2001 15:12:38 +0300
Local: Fri 19 Oct 2001 13:12
Subject: Re: __FUNCTION__ ????

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.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lawrence Kirby  
View profile   Translate to Translated (View Original)
 More options 19 Oct 2001, 15:37
Newsgroups: comp.lang.c
From: f...@genesis.demon.co.uk (Lawrence Kirby)
Date: Fri, 19 Oct 2001 12:44:14 GMT
Local: Fri 19 Oct 2001 13:44
Subject: Re: __FUNCTION__ ????
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.

Any good tutorial book on C should give one.

There is a standard defined macro named assert(), this is an unwise name
to define in your code.

--
-----------------------------------------
Lawrence Kirby | f...@genesis.demon.co.uk
Wilts, England | 70734....@compuserve.com
-----------------------------------------


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CBFalconer  
View profile   Translate to Translated (View Original)
 More options 19 Oct 2001, 21:20
Newsgroups: comp.lang.c
From: CBFalconer <cbfalco...@yahoo.com>
Date: Fri, 19 Oct 2001 20:20:37 GMT
Local: Fri 19 Oct 2001 21:20
Subject: Re: __FUNCTION__ ????

Kalle Olavi Niemitalo wrote:

> sob...@eudoramail.com (Sobhan Vezzu) writes:

... snip ...

> >          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.

Well, that was interesting.  Adapted to MSDOS/DJGPP, it gives:

c:\dnld\scratch>gcc -E -dM -xc nul
#define __DJGPP_MINOR 3
#define __i386__ 1
#define __GO32__ 1
#define __i386 1
#define GO32 1
#define __GNUC_MINOR__ 95
#define __DJGPP__ 2
#define __tune_pentium__ 1
#define __DJGPP 2
#define i386 1
#define __MSDOS 1
#define __MSDOS__ 1
#define __unix 1
#define DJGPP_MINOR 3
#define __unix__ 1
#define __GNUC__ 2
#define DJGPP 2
#define MSDOS 1
#define __DJGPP_MINOR__ 3
#define unix 1
#define __GO32 1

--
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)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "__FUNCTION__ ?" by ralmin
ralmin  
View profile   Translate to Translated (View Original)
 More options 20 Oct 2001, 13:43
Newsgroups: comp.lang.c
From: "ralmin" <sbi...@optushome.com.au>
Date: Sat, 20 Oct 2001 22:44:56 +1000
Local: Sat 20 Oct 2001 13:44
Subject: Re: [OT] __FUNCTION__ ?
"Kalle Olavi Niemitalo" <k...@iki.fi> wrote:

> 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.

Why only on Unix?

C:\>gcc -ansi -E -dM -xc /dev/null
#define __STRICT_ANSI__ 1
#define __i386__ 1
#define _X86_ 1
#define __i386 1
#define __i686 1
#define __GNUC_MINOR__ 95
#define __declspec(x) __attribute__((x))
#define __CYGWIN__ 1
#define __pentiumpro 1
#define __pentiumpro__ 1
#define __stdcall __attribute__((__stdcall__))
#define __unix 1
#define __unix__ 1
#define __i686__ 1
#define __GNUC__ 2
#define __cdecl __attribute__((__cdecl__))
#define __CYGWIN32__ 1

Ralmin.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

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