On use of C99 __func__ macro

  • Thread starter Guillaume Dargaud
  • Start date
G

Guillaume Dargaud

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;
}
 
V

vippstar

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

Björn Paetzel

On Dec 5, 1:29 pm, "Guillaume Dargaud"

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

Richard Tobin

Guillaume Dargaud said:
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
 
N

Neil Booth

Richard said:
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.
 
R

Richard Tobin

Yes, because __func__ is required to be like a variable, rather than
a preprocessor macro.
[/QUOTE]
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
 
G

Guillaume Dargaud

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top