Results 1 to 2 of 2
  1. #1

    Member Since
    Apr 19, 2010
    Pointer being cast 32-bit in function return
    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.


  2. #2

    Member Since
    Jun 25, 2009
    Plaistow, W.Sx. UK
    iMac 8,1 2.8GHz Core 2 Duo 4GB, Yosemite 10.10.3
    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?



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How Do I Keep My Mouse Pointer To Always Stay As A Pointer?
    By Cycling Warrior in forum OS X - Operating System
    Replies: 4
    Last Post: 12-17-2014, 01:38 PM
  2. Upgrading EFI from 32-bit to 64-bit on Mac Pro with 64-bit processor
    By Gemless Ear in forum OS X - Operating System
    Replies: 4
    Last Post: 04-21-2014, 12:55 AM
  3. return or not to IMac desktop
    By berlyniki in forum Apple Desktops
    Replies: 6
    Last Post: 12-11-2009, 07:51 PM
  4. Mouse pointer is "walking" across the screen. Return it?
    By fleurya in forum Other Hardware and Peripherals
    Replies: 4
    Last Post: 03-17-2008, 05:14 PM
  5. To return or not to return...give me your opinion.
    By iBrad in forum Apple Notebooks
    Replies: 6
    Last Post: 05-25-2006, 08:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts