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

/**
  An example to demostrate an unexpected function overload...
  
  MyPrintf(fmt, char*) calls MyPrintf(fmt, va_list&) 
  instead of MyPrintf(fmt, ...)
  
  MyPrintf(fmt, const char*) calls as expected MyPrintf(fmt, ...)
  
*/


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