Unexpected function overloading

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have two functions MyPrintf(const char *fmt, ...) and MyPrintf(const
char *fmt, va_list& vargs).

I expect MyPrintf(fmt, str) to call MyPrintf(fmt, ...) but it happens
only when 'str' is a const char*.
When 'str' is a char* MyPrintf(fmt, va_list&) is called.

Is this the right behaviour ?


Code :  http://ideone.com/1Zc5j

-- 
Thanks,
Sundararaj


PS: The __PRETTY_FUNCTION__ macro in MyPrintf(const char*, va_list&)
reports the function as MyPrintf(const char*, char* &). Does it
indicate some "confusion" inside gcc (g++) ?




/*---------------------------------------*/


#include <cstdarg>
#include <cstring>
#include <cstdio>

void MyPrintf(const char* fmt, ...)
{
        printf("%s ('%s')\n", __PRETTY_FUNCTION__, fmt);
}

void MyPrintf(const char* fmt, va_list& vargs)
{
        printf("%s ('%s', vargs='%p')\n", __PRETTY_FUNCTION__, fmt, &vargs);
}


int main()
{
        char* str = strdup("hello all\n");
        printf("str@ %p\n", str);

        MyPrintf("%s", (const char*) str); // calls MyPrintf(fmt, ...)
        MyPrintf("%s", str);                    // calls MyPrintf(fmt, va_list&)

        return 0;
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux