Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » pitfall with storing integers in a stream
pitfall with storing integers in a stream [message #60292] Mon, 13 November 2023 12:04
piotr5 is currently offline  piotr5
Messages: 107
Registered: November 2005
Experienced Member
#include <Core/Core.h>
CONSOLE_APP_MAIN
{
	size_t num=int(-1);
	size_t small=9999;
	StringStream dump;
	dump.SetStoring();
	dump % small;
	dump.SetLoading();
	dump.Seek(0);
	dump % num;
	Cout()<<num;
}

18446744069414594319

compiled with gcc or clang on a 64-bit cpu will store only the lower 32 bit and restore it in-place leaving the higher 32 bit untouched resulting in above number. Stream::operator/ works as expected though. strangely replacing size_t by uint64 makes the problem go away too. if this is intentional, I haven't seen it mentioned in the help topics...
Previous Topic: Bugfix: XmlParser in endless loop
Next Topic: About recent memset optimization
Goto Forum:
  


Current Time: Sun Apr 28 21:29:21 CEST 2024

Total time taken to generate the page: 0.06740 seconds