__FUNCTION__

R

Ravi

Hi,

I have a crash and when i decode the stack, i see that it points to a
printf. The line is :

printf("\n" __FUNCTION__ ": 0x%x dup_req:%d", addr,
xf_xredun_info.valid);

Is there something wrong with the way __FUNCTION__ is passed ?

TIA
Ravi
 
W

Walter Roberson

Ravi said:
I have a crash and when i decode the stack, i see that it points to a
printf. The line is :
printf("\n" __FUNCTION__ ": 0x%x dup_req:%d", addr,
xf_xredun_info.valid);
Is there something wrong with the way __FUNCTION__ is passed ?

Looks okay to me. However, %x takes an unsigned int as its
argument, and your use of 'addr' suggests that you are passing
a pointer instead of an unsigned int.

Also, a crash in a printf can sometimes happen if you have
corrupted memory somehow, such as by writing before or after
the end of a malloc()'d space, or free()'ing a pointer twice.
 
K

Keith Thompson

Ravi said:
I have a crash and when i decode the stack, i see that it points to a
printf. The line is :

printf("\n" __FUNCTION__ ": 0x%x dup_req:%d", addr,
xf_xredun_info.valid);

Is there something wrong with the way __FUNCTION__ is passed ?

__FUNCTION__ is non-standard.

__func__ is standard (at least in C99), but it's a predefined
identifier, not a macro expanding to a string literal; if you want to
print it (assuming your compiler supports it), you'll need to use a
"%s" format.

Make sure that addr is of type unsigned int, and xf_xredun_info.valid
is of type int. If addr is an address / pointer, you need to use
"%p" to print it:

printf("addr = %p\n", (void*)addr);
 
C

CBFalconer

Ravi said:
I have a crash and when i decode the stack, i see that it points
to a printf. The line is :

printf("\n" __FUNCTION__ ": 0x%x dup_req:%d", addr,
xf_xredun_info.valid);

Is there something wrong with the way __FUNCTION__ is passed ?

Probably. First, we can't tell, because you didn't include its
definition. Secondly, its name is invading a namespace reserved
for the implementor. Avoid all leading '_' characters.

The personal pronoun 'I' is spelt with a capital 'I'.
 
R

Richard Tobin

printf("\n" __FUNCTION__ ": 0x%x dup_req:%d", addr,
xf_xredun_info.valid);

Is there something wrong with the way __FUNCTION__ is passed ?
[/QUOTE]
Probably. First, we can't tell, because you didn't include its
definition. Secondly, its name is invading a namespace reserved
for the implementor. Avoid all leading '_' characters.

Presumably __FUNCTION__ is something provided by the implementor,
so it's quite right for it to start with an underscore.

-- Richard
 
K

Keith Thompson

CBFalconer said:
Probably. First, we can't tell, because you didn't include its
definition. Secondly, its name is invading a namespace reserved
for the implementor. Avoid all leading '_' characters.

__FUNCTION__ is an extension provided by gcc (and perhaps by other
compilers); it's replaced by a string literal containing the name of
the current function. Since __FILE__ and __LINE__ are standard, I'd
say the OP can be forgiven for not realizing that __FUNCTION__ isn't.

There is no source for it (unless you want the OP to post the gcc
sources), and it starts with "__" because it needs to.
 
R

Richard

Ravi said:
Hi,

I have a crash and when i decode the stack, i see that it points to a
printf. The line is :

printf("\n" __FUNCTION__ ": 0x%x dup_req:%d", addr,
xf_xredun_info.valid);

Is there something wrong with the way __FUNCTION__ is passed ?

TIA
Ravi

try this:

printf("\n%s : 0x%x dup_req:%d", __FUNCTION__ ,addr, .....
 
R

Richard Bos

Richard said:
try this:

printf("\n%s : 0x%x dup_req:%d", __FUNCTION__ ,addr, .....

Or rather, don't, because __FUNCTION__ is still non-Standard. Try,
instead,

printf(\n%s: 0x%x dup_req:%d", __func__, addr, xf_xredun_info.valid);

but first chect that addr really is an unsigned int, and that
xf_xredun_info.valid really is an int (and not unsigned).

Richard
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top