Hi aval57,
I just tried it myself (wxGTK 2.6.2 ANSI), gcc 4.0.3 20051201.
Funnily enough, it's the other way around here: the second call works, the first doesn't.
I implemented this with overloaded methods and it works:
Code: Select all
#include <cstdlib>
#include <iostream>
#include <wx/string.h>
using namespace std;
void echo2(uint32_t i,const char *s ){
cout << wxString::Format( "%u %s ", i, s ) << "\n";
}
void echo2(uint64_t i,const char *s ){
cout << wxString::Format( "%Lu %s ", i, s ) << "\n";
}
template<class T>
void echo( T i, const char *s )
{
cout << wxString::Format( "%Lu %s ", i, s ) << "\n"; // line 18
}
int main(int argc, char *argv[])
{
echo( (uint32_t)2, "hello world" ); // line 23
echo( (uint64_t)2, "hello world");
cout << "overloaded: " << endl;
echo2( (uint32_t)2, "hello world" );
echo2( (uint64_t)2, "hello world");
}
Output:
579523549316775938
2 hello world
overloaded:
2 hello world
2 hello world
Please note the compiler complains with -Wall:
test.cpp: In function 'void echo(T, const char*) [with T = unsigned int]':
test.cpp:23: instantiated from here
test.cpp:18: warning: format '%Lu' expects type 'long long unsigned int', but argument 2 has type 'unsigned int'
A few things:
1: %L is actually correct as it seems (for long longs)
2: I'm surprised that the call with the uint32_t doesn't work. uint32_t is type compatible with uint64_t, so it should work.
3: A plain printf shows the same faulty output as wxString::Format() does, so I doubt it's a bug in wx (wx uses the clibs printf, iirc).
However, going with overloads should help.
Chris