| OS X - Development and Darwin Discussion and questions about development for Mac OS X. |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Apr 19, 2010
Posts: 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. |
| QUOTE Thanks | |
![]() Member Since: Jun 25, 2009
Location: Plaistow, W.Sx. UK
Posts: 22
![]() Mac Specs: iMac 8,1 2.8GHz Core 2 Duo 4GB, SL 10.6.4
|
Hi Antarctican
What is the actual code at line 24 in cdriver.c? cdriver.c:24: warning: cast to pointer from integer of different size implies that, although the compiler can compile the code, it is doubtful that you will get the result you want/expect. The compiler is saying that you are implicitly casting from an integer to a pointer. Is the prototype definition correct? Can you post a bit more of the code, especially line 24, and the variable definitions please? Cheers Smudger |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| 32 bit or 64 bit vista for macbook? | stephenheath30 | Running Windows (or anything else) on your Mac | 3 | 01-01-2008 09:01 AM |
| Noobish question | floyd923 | Schweb's Lounge | 6 | 02-14-2007 08:44 PM |
| 64 bit on Macs | DrQuincy | Switcher Hangout | 9 | 01-26-2007 11:23 PM |
| 64 bit and what does it all mean? | JamminJonah | Other Hardware and Peripherals | 9 | 08-11-2006 04:02 PM |
| osx install blue screen hell | David123 | OS X - Operating System | 10 | 08-22-2004 04:40 PM |
All times are GMT -4. The time now is 04:16 PM.
Powered by vBulletin