Domanda

It's C/Linux env.

I'm thinking whether it's possible. I have an app which need to talk to each other between 32bit and 64bit platform. In its heartbeat, there is a structure like:

typedef struct{

          ..... //usual data type
          unit32_t* old;
          unit32_t* new;

}heartbeat;

The two pointers take 8 bytes in 32, but take 16 bytes in 64. It makes the size of the heartbeat different and also the possible misinterpreting of the pointers. The only code I can modify is the ones in 64bit platform. Is there any way to go around the issue?

Thanks

È stato utile?

Soluzione

First of all you must be aware that for the "other" process the pointer cannot be seen as pointer.

You can modify the pointer but not read data from the pointer or write data to it.

The idea to use "int32_t" of "Kerrek SB" would make sense in this case; however using "uint64_t" is more useful because this would allow the 32-bit process to modify a pointer pointing to an address space that is larger than 4 GiB:

typedef union {
    uint32_t *ptr;
    uint64_t address;
} maxaddr;

Instead of using "hb.old++" you would use "hb.old.address+=sizeof(uint32_t)".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top