Printf error i don't understand Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Printf error i don't understand

Post by Parduz »

This is an extract of my code:

Code: Select all

wxString		str;
size_t		FileCount;

FileCount = wxDir::GetAllFiles(*DirName, &FileList, RB_Filter, wxDIR_FILES	);
if (FileCount<1) {
	for (size_t i=0; i<FileCount; i++) {
		// Create file label
		str.Printf("%u/%u",i+1,FileCount);
		m_RED_lFileCount = new wxStaticText(m_MyFileScroller, wxID_ANY, str, wxDefaultPosition, wxSize(-1,-1), wxST_NO_AUTORESIZE|wxALIGN_RIGHT);

		// ....

On the printf line i get this error:
errore.png
errore.png (8.99 KiB) Viewed 310 times
I tried debugging it, using wxT("%u/%u") but i really don't get what is wrong in that Printf.
User avatar
doublemax
Moderator
Moderator
Posts: 17819
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Printf error i don't understand

Post by doublemax »

size_t is not necessarily the same type as "unsigned int". Check what type it is, e.g. if it's a "long long", use "%llu" as format specifier. Or you could just cast the variable down to "unsigned int".
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 3696
Joined: Sun Jan 03, 2010 5:45 pm

Re: Printf error i don't understand

Post by PB »

sizeof size_t depends on the build, it is basically the same as the pointer, i.e., 4 bytes in 32-bit and 8 bytes in 64-bit build.

Just use the correct specifier for size_t, i.e., "%zu". wxWidgets added support for it many years ago.
Post Reply