Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > On use of C99 __func__ macro

Reply
Thread Tools

On use of C99 __func__ macro

 
 
Guillaume Dargaud
Guest
Posts: n/a
 
      12-05-2007
Hello all,
Is it the same thing to do those two things:

#define WHERE printf("We are in %s", __func__)
void Function(void) {
WHERE;
}

And this:

void Function(void) {
#define WHERE printf("We are in %s", __func__)
WHERE;
}


--
Guillaume Dargaud
http://www.gdargaud.net/
"What is it about a man's cell phone going off in a theater that makes him
look more and more like Abe Lincoln ? - Jerry L. Embry.


 
Reply With Quote
 
 
 
 
vippstar@gmail.com
Guest
Posts: n/a
 
      12-05-2007
On Dec 5, 1:29 pm, "Guillaume Dargaud"
<(E-Mail Removed) t> wrote:
> Hello all,
> Is it the same thing to do those two things:
>
> #define WHERE printf("We are in %s", __func__)
> void Function(void) {
> WHERE;
>
> }
>
> And this:
>
> void Function(void) {
> #define WHERE printf("We are in %s", __func__)
> WHERE;
>
> }


There's no __func__ in C99.
 
Reply With Quote
 
 
 
 
Björn Paetzel
Guest
Posts: n/a
 
      12-05-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) schrieb:
> On Dec 5, 1:29 pm, "Guillaume Dargaud"
> <(E-Mail Removed) t> wrote:


>> #define WHERE printf("We are in %s", __func__)
>> void Function(void) {
>> WHERE;
>>
>> }
>>
>> And this:
>>
>> void Function(void) {
>> #define WHERE printf("We are in %s", __func__)
>> WHERE;
>>
>> }


Yes. Both expands to:

void Function(void) {
printf("We are in %s", __func__);

}

> There's no __func__ in C99.


There is.

6.4.2.2 #1 says:

The identifier __func__ shall be implicitly declared by the translator
as if, immediately following the opening brace of each function
definition, the declaration

static const char __func__[] = "function-name";

appeared, where function-name is the name of the lexically- enclosing
function.

--
OMG,-10==10 in linux!
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      12-05-2007
In article <fj621u$a9s$(E-Mail Removed)2p3.fr>,
Guillaume Dargaud <(E-Mail Removed) t> wrote:

>Is it the same thing to do those two things:
>
>#define WHERE printf("We are in %s", __func__)
>void Function(void) {
> WHERE;
>}
>
>And this:
>
>void Function(void) {
> #define WHERE printf("We are in %s", __func__)
> WHERE;
>}


Yes, because __func__ is required to be like a variable, rather than
a preprocessor macro.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      12-05-2007
(E-Mail Removed) wrote:

> On Dec 5, 1:29 pm, "Guillaume Dargaud"
> <(E-Mail Removed) t> wrote:
>> Hello all,
>> Is it the same thing to do those two things:
>>
>> #define WHERE printf("We are in %s", __func__)
>> void Function(void) {
>> WHERE;
>>
>> }
>>
>> And this:
>>
>> void Function(void) {
>> #define WHERE printf("We are in %s", __func__)
>> WHERE;
>>
>> }

>
> There's no __func__ in C99.


C & V please.

 
Reply With Quote
 
Jalapeno
Guest
Posts: n/a
 
      12-05-2007
On Dec 5, 8:43 am, santosh <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On Dec 5, 1:29 pm, "Guillaume Dargaud"
> > <(E-Mail Removed) t> wrote:
> >> Hello all,
> >> Is it the same thing to do those two things:

>
> >> #define WHERE printf("We are in %s", __func__)
> >> void Function(void) {
> >> WHERE;

>
> >> }

>
> >> And this:

>
> >> void Function(void) {
> >> #define WHERE printf("We are in %s", __func__)
> >> WHERE;

>
> >> }

>
> > There's no __func__ in C99.

>
> C & V please.- Hide quoted text -
>


Why it's right here:

http://www.youtube.com/watch?v=6lj9_zBobJs
 
Reply With Quote
 
vippstar@gmail.com
Guest
Posts: n/a
 
      12-05-2007
On Dec 5, 3:43 pm, santosh <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On Dec 5, 1:29 pm, "Guillaume Dargaud"
> > <(E-Mail Removed) t> wrote:
> >> Hello all,
> >> Is it the same thing to do those two things:

>
> >> #define WHERE printf("We are in %s", __func__)
> >> void Function(void) {
> >> WHERE;

>
> >> }

>
> >> And this:

>
> >> void Function(void) {
> >> #define WHERE printf("We are in %s", __func__)
> >> WHERE;

>
> >> }

>
> > There's no __func__ in C99.

>
> C & V please.


I answered from memory.
Can't always be right on usenet
 
Reply With Quote
 
Neil Booth
Guest
Posts: n/a
 
      12-05-2007
Richard Tobin wrote:
> In article <fj621u$a9s$(E-Mail Removed)2p3.fr>,
> Guillaume Dargaud <(E-Mail Removed) t> wrote:
>
>> Is it the same thing to do those two things:
>>
>> #define WHERE printf("We are in %s", __func__)
>> void Function(void) {
>> WHERE;
>> }
>>
>> And this:
>>
>> void Function(void) {
>> #define WHERE printf("We are in %s", __func__)
>> WHERE;
>> }

>
> Yes, because __func__ is required to be like a variable, rather than
> a preprocessor macro.


Not "because": even if it were a macro the answer would still be yes.

Neil.
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      12-05-2007
In article <4756bd29$0$287$(E-Mail Removed)-net.or.jp>,
Neil Booth <dev@null> wrote:

>>> Is it the same thing to do those two things:
>>>
>>> #define WHERE printf("We are in %s", __func__)
>>> void Function(void) {
>>> WHERE;
>>> }
>>>
>>> And this:
>>>
>>> void Function(void) {
>>> #define WHERE printf("We are in %s", __func__)
>>> WHERE;
>>> }


>> Yes, because __func__ is required to be like a variable, rather than
>> a preprocessor macro.


>Not "because": even if it were a macro the answer would still be yes.


Um yes. I should have said "... rather than some magic thing that
gets replaced when it is first encountered in the text".

-- Richard

--
:wq
 
Reply With Quote
 
Guillaume Dargaud
Guest
Posts: n/a
 
      12-05-2007
>>Not "because": even if it were a macro the answer would still be yes.

> Um yes. I should have said "... rather than some magic thing that
> gets replaced when it is first encountered in the text".


Thanks, that sums it up nicely.
--
Guillaume Dargaud
http://www.gdargaud.net/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between "library parts" of C99 and "language parts" of C99 albert.neu@gmail.com C Programming 3 03-31-2007 08:14 PM
How to test for the existence of __func__? dave_140390@hotmail.com C Programming 9 10-26-2006 08:24 PM
C99 struct initialization (C99/gcc) jilerner@yahoo.com C Programming 3 02-20-2006 04:41 AM
__func__ macro emulation chasdev C++ 2 10-30-2003 10:25 AM
curiosity question regarding __func__ djinni C Programming 2 08-13-2003 04:52 AM



Advertisments