468,457 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

On use of C99 __func__ macro

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.
Dec 5 '07 #1
10 7748
On Dec 5, 1:29 pm, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.netw rote:
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.
Dec 5 '07 #2
vi******@gmail.com schrieb:
On Dec 5, 1:29 pm, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.netw rote:
>#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!
Dec 5 '07 #3
In article <fj**********@ccpntc8.in2p3.fr>,
Guillaume Dargaud <us*****************************@www.gdargaud.netw rote:
>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.
Dec 5 '07 #4
vi******@gmail.com wrote:
On Dec 5, 1:29 pm, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.netw rote:
>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.

Dec 5 '07 #5
On Dec 5, 8:43 am, santosh <santosh....@gmail.comwrote:
vipps...@gmail.com wrote:
On Dec 5, 1:29 pm, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.netw rote:
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
Dec 5 '07 #6
On Dec 5, 3:43 pm, santosh <santosh....@gmail.comwrote:
vipps...@gmail.com wrote:
On Dec 5, 1:29 pm, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.netw rote:
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 :-)
Dec 5 '07 #7
Richard Tobin wrote:
In article <fj**********@ccpntc8.in2p3.fr>,
Guillaume Dargaud <us*****************************@www.gdargaud.netw rote:
>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.
Dec 5 '07 #8
In article <47*********************@news2.asahi-net.or.jp>,
Neil Booth <dev@nullwrote:
>>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
Dec 5 '07 #9
>>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/
Dec 5 '07 #10
vi******@gmail.com wrote:
>
There's no __func__ in C99.
Just for the record, there is a __func__ in C99, ref. 6.4.2.2.

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 9 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by chasdev | last post: by
20 posts views Thread by Jim Ford | last post: by
19 posts views Thread by Mockey Chen | last post: by
9 posts views Thread by dave_140390 | last post: by
1 post views Thread by somenath | last post: by
33 posts views Thread by Peng Yu | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.