This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C Programming and pointer sizes on ARM processors.

Hi,

I've a question regarding C programming on ARM processors. can I ALWAYS assume that the sizeof(function_pointers) == sizeof(void *) == sizeof(char *)? Also I read in a blog (Caches and Self-Modifying Code) that "ARM architecture is often considered to be a Modified Harvard Architecture" does this mean the instructions are placed in a different memory space than the data memory space?  If so again how can we guarantee the sizeof (function_pointer) == sizeof(data_pointer)?

Thanks.

Parents
  • I've a question regarding C programming on ARM processors. Can I ALWAYS assume that the sizeof(function_pointers) == sizeof(void *) == sizeof(char *)?

    "Guarantee" - no. If you are coding to the standard then C provides no guarantees that function pointers are the same width as data pointers (conceptually allowing function pointers to carry around additional payload in addition to an address).

    "Pragmatically assume" - probably - I'm not aware of any cases where the two differ in reality. Data pointers will always be the same data width, as C allows cast to void* and back again, so that "has to work".

    If so again how can we guarantee the sizeof (function_pointer) == sizeof(data_pointer)?

    You can't - if you rely on this you are coding outside of the standard. The best thing to do would be to add some compile time asserts to raise an error if the two ever differ. That said, as above, it is highly highly probable to be true on every implementation I can think of, so it is unlikely you will run into any problems ...


    HTH,

    Pete

Reply
  • I've a question regarding C programming on ARM processors. Can I ALWAYS assume that the sizeof(function_pointers) == sizeof(void *) == sizeof(char *)?

    "Guarantee" - no. If you are coding to the standard then C provides no guarantees that function pointers are the same width as data pointers (conceptually allowing function pointers to carry around additional payload in addition to an address).

    "Pragmatically assume" - probably - I'm not aware of any cases where the two differ in reality. Data pointers will always be the same data width, as C allows cast to void* and back again, so that "has to work".

    If so again how can we guarantee the sizeof (function_pointer) == sizeof(data_pointer)?

    You can't - if you rely on this you are coding outside of the standard. The best thing to do would be to add some compile time asserts to raise an error if the two ever differ. That said, as above, it is highly highly probable to be true on every implementation I can think of, so it is unlikely you will run into any problems ...


    HTH,

    Pete

Children
No data