Variables in memory cross-platform... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Variables in memory cross-platform...

SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
Alright, this is a bit of a bugger, but it has to be done this way to avoid bloated code. I am reading a file into memory that was written in 16bit DOS. Due to this, variable sizes do not match. This means that a 64bit long is much larger than the 16bit long stored in the data in memory. How can I take the four-byte long in memory and read it into an eight-byte long on my 64bit system? I need a method that is fairly quick since I'll be reading various data into various variables semi-frequently and I can't have pausing while it reads the old data into a new variable.



  • janssonjansson Posts: 1Member
    How about something like the following? (Assuming you have the types in32_t and int64_t that can hold your data.)

    [code]int32_t i;
    istream::read( (char*)&i, 4 );
    int64_t j = i;[/code]

  • LundinLundin Posts: 3,711Member
    Read it as "short"? short is 16 bits on every platform.
Sign In or Register to comment.