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
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...
|
|
|
Goto Forum:
Current Time: Wed May 15 05:10:23 CEST 2024
Total time taken to generate the page: 0.02801 seconds
|