- Joined
- Apr 19, 2010
- Messages
- 1
- Reaction score
- 0
- Points
- 1
Good morning,
I have some C code which I'm trying to port to OS X (Snow Leopard) and I'm having trouble with a pointer I'm returning getting truncated to 32-bits when it's returned from a call.
The prototype for the callee is:
helix_sites* get_helices(char*, char*, char*, char*);
Where helix_sites is previously defined as a struct:
typedef struct {
int helix_count;
struct helix_sites *helix;
} helix_sites;
In the callee function get_helices I successfully make a call to malloc:
helix_sites* hSites;
....
hSites = (helix_sites *) malloc_or_die(sizeof (helix_sites));
....
return hSites;
In ddd I see the pointer is 64-bit, I successfully use the new structure, all is fine. However when I return this pointer to the caller which accepts the pointer in its own helix_sites* variable the
pointer somehow gets truncated to 32-bits. I can see this as well when checking with ddd, the upper 32-bits of the pointer are suddenly missing.
The compiler gives a warning:
cdriver.c:24: warning: cast to pointer from integer of different size
I can only guess this has something to do with how the return value is passed on the stack, that a 64-bit slot isn't allocated since both the caller and callee are using 64-bit pointers for the
variable.
I've tried swapping in void* pointers as a test then casting it to the helix_sites* type, no luck with that either, which definitely says its on the compiler/runtime side.
Any advice would be welcome, if there are any known issues with returning pointers in C compiling with gcc under Snow Leopard or such.
Thanks.
I have some C code which I'm trying to port to OS X (Snow Leopard) and I'm having trouble with a pointer I'm returning getting truncated to 32-bits when it's returned from a call.
The prototype for the callee is:
helix_sites* get_helices(char*, char*, char*, char*);
Where helix_sites is previously defined as a struct:
typedef struct {
int helix_count;
struct helix_sites *helix;
} helix_sites;
In the callee function get_helices I successfully make a call to malloc:
helix_sites* hSites;
....
hSites = (helix_sites *) malloc_or_die(sizeof (helix_sites));
....
return hSites;
In ddd I see the pointer is 64-bit, I successfully use the new structure, all is fine. However when I return this pointer to the caller which accepts the pointer in its own helix_sites* variable the
pointer somehow gets truncated to 32-bits. I can see this as well when checking with ddd, the upper 32-bits of the pointer are suddenly missing.
The compiler gives a warning:
cdriver.c:24: warning: cast to pointer from integer of different size
I can only guess this has something to do with how the return value is passed on the stack, that a 64-bit slot isn't allocated since both the caller and callee are using 64-bit pointers for the
variable.
I've tried swapping in void* pointers as a test then casting it to the helix_sites* type, no luck with that either, which definitely says its on the compiler/runtime side.
Any advice would be welcome, if there are any known issues with returning pointers in C compiling with gcc under Snow Leopard or such.
Thanks.