New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Pointer being cast 32-bit in function return

Post Reply New Thread Subscribe

Thread Tools

Member Since: Apr 19, 2010
Posts: 1
antarctican is on a distinguished road

antarctican is offline
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

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.

QUOTE Thanks

Member Since: Jun 25, 2009
Location: Plaistow, W.Sx. UK
Posts: 23
Smudger is on a distinguished road
Mac Specs: iMac 8,1 2.8GHz Core 2 Duo 4GB, Yosemite 10.10.3

Smudger is offline
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?


QUOTE Thanks

Post Reply New Thread Subscribe

« Interacting through one program with other programs | Best programming language for Mac »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
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 06:26 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?