Discussion in 'C Programming' started by Ravi, Sep 27, 2007.

  1. Ravi

    Ravi Guest


    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,

    Is there something wrong with the way __FUNCTION__ is passed ?

    Ravi, Sep 27, 2007
    1. Advertisements

  2. 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.
    Walter Roberson, Sep 27, 2007
    1. Advertisements

  3. __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);
    Keith Thompson, Sep 27, 2007
  4. Ravi

    CBFalconer Guest

    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'.
    CBFalconer, Sep 27, 2007
  5. [/QUOTE]
    Presumably __FUNCTION__ is something provided by the implementor,
    so it's quite right for it to start with an underscore.

    -- Richard
    Richard Tobin, Sep 28, 2007
  6. __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.
    Keith Thompson, Sep 28, 2007
  7. Ravi

    Richard Guest

    try this:

    printf("\n%s : 0x%x dup_req:%d", __FUNCTION__ ,addr, .....
    Richard, Sep 28, 2007
  8. Ravi

    Richard Bos Guest

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

    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 Bos, Sep 28, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.