Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo



  • Matt Bucknall
    Matt Bucknall


    Is there any particular reason why ptrdiff_t appears to be missing from stddef.h in SDCC's standard library?


  • Maarten Brock
    Maarten Brock

    Hi Matt,

    It depends on the architecture whether ptrdiff_t can be easily defined or not. For VonNeumann architectures like z80 it is no problem. But for Harvard architectures where every memory space can have its own size (and does e.g. mcs51) it is more difficult. We could always use the upper bound resulting in unoptimized code which contradicts the intention of ptrdiff_t.


  • Matt Bucknall
    Matt Bucknall

    How does the compiler then decide on the size pointers?

    My understanding is that ptrdiff_t is intended as the type for a result obtained by subtracting one pointer from another. It exists merely to assist in performing correct (and not necessarily optimum) pointer arithmetic.

    I would have thought a sub-optimally sized ptrdiff_t would be better than omitting it completely for Harvard architectures. Surely it should be the programmer's decision as to whether they want to use the type or not? At least including it would aid in porting existing code over to SDCC (which is what I happen to be doing at the moment).