c-plus-plus-serializer icon indicating copy to clipboard operation
c-plus-plus-serializer copied to clipboard

values arent read correctly

Open PerspectivesLab opened this issue 1 year ago • 2 comments
trafficstars

Hi the values read arent working, on windows, visual studio:

std::cout << "save to " << filename << std::endl;
std::ofstream out(filename, std::ios::binary);
char                          a = 42;
unsigned short         b = 65535;
int                           c = 123456;
out << bits(c) << bits(b) << bits(c)  ;

is read:

a: char @ b: unsigned short : 482 c: int 1090518784

with read code :

    char                          a;
    unsigned short         b;
    int                           c;
    in >> bits(a) >> bits(b) >> bits(c)  ;
    std::cout << std::endl;
    std::cout << "read:" << std::endl;
    std::cout << "  a: char                     " << a << std::endl;
    std::cout << "  b: unsigned short           " << b << std::endl;
    std::cout << "  c: int                      " << c << std::endl;

    std::cout << std::endl;

PerspectivesLab avatar Apr 22 '24 15:04 PerspectivesLab

weird - you could enable DEBUG_C_PLUS_PLUS_SERIALIZER to see what it's doing more - confusing...

On Mon, 22 Apr 2024 at 16:43, Perspective[S] @.***> wrote:

Hi the values read arent working, on windows, visual studio:

std::cout << "save to " << filename << std::endl; std::ofstream out(filename, std::ios::binary); char a = 42; unsigned short b = 65535; int c = 123456; out << bits(c) << bits(b) << bits(c) ;

is read:

a: char @ b: unsigned short : 482 c: int 1090518784

with read code :

char                          a;
unsigned short         b;
int                           c;
in >> bits(a) >> bits(b) >> bits(c)  ;
std::cout << std::endl;
std::cout << "read:" << std::endl;
std::cout << "  a: char                     " << a << std::endl;
std::cout << "  b: unsigned short           " << b << std::endl;
std::cout << "  c: int                      " << c << std::endl;

std::cout << std::endl;

— Reply to this email directly, view it on GitHub https://github.com/goblinhack/c-plus-plus-serializer/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADA3H4OSLK2TISUDYFMLBTY6UVZNAVCNFSM6AAAAABGTBH7GSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2TMOBXHA4TONQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

goblinhack avatar Apr 22 '24 18:04 goblinhack

It sounds like vis studio is picking up the incorrect template for short/int - the debug might help show which

another option is to try to enable USE_SIZE_T

goblinhack avatar Apr 23 '24 08:04 goblinhack