maintain size of pointer in 32bit to 64 bit machine

I have very legacy code which migrate from 32 bit machine to 64 bit machine.During my analysis we do lot of calculation on the bit basis.So it might be issue for corrupting data.

So I want to try with size of pointer 4 byte in 64 bit, is it possible that we can declair pointer of 4 byte in 64 machine.The reason for reducing size as we do not have large value. most value varies between 1000 to 10000.

In Legacy code,it contain following union.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
using namespace std;

class  sample
{
public:

  union
    {
    short    *two_int;
    int     *four_int;
    double   *eight_real;
    char     *one_ascii;
    };
};

int main()
{
    cout<<sizeof(sample)<<endl;
    short    *two_int;
    int     *four_int;
    double   *eight_real;
    char     *one_ascii;
    int data;
    double eight;
    cout<<"two int.... "<<sizeof(two_int)<<endl;
    cout<<"four_int .... "<<sizeof(four_int)<<endl;
    cout<<"eight_real... "<<sizeof(eight_real)<<endl;
    cout<<"one... "<<sizeof(one_ascii)<<endl;
    cout<<" int size .... "<<sizeof(data)<<endl;
    cout<<" double... size ... "<<sizeof(eight)<<endl;
    return 0;
}


I have posted question in detail information in below link.
http://stackoverflow.com/questions/17447838/migration-c-code-32-bit-machine-to-64-bit-machine
Last edited on
Why are you worried about the size of the pointers? The number of bytes written to and read from the file will have absolutely nothing to do with the size of the pointers. The size of what they point to is a different story. You might find http://en.cppreference.com/w/cpp/types/integer useful for that.
No, its not possible to specify pointer size. the compiler will make them whatever the cpu requires them to be.

16bit machines use a 16bit pointer (2 bytes) max address range is 64KB

32bit machines use a 32bit pointer (4 bytes) max address range is 4 gigabytes

64bit machines use a 64bit pointer (8 bytes) max address range is 16 exbibytes

some 16bit machines had near and far pointers which was a way of accessing many 64KB blocks, and that is how PC's got started and why a 16bit PC could have 512KB or even 640KB of RAM while other 16bit computers still had only 64KB.

cire has the real answer for you, declare your data with the new types identified in cire's link.

edited to add link:
lots of 32/64 porting issues are discussed here http://www.viva64.com/en/a/0004/
Last edited on
Thanks for reply and share useful link
Topic archived. No new replies allowed.