Hacker News new | past | comments | ask | show | jobs | submit login

The main thing in my post is how we get that input value, in your case SIZE_T_BITS, at the preprocessing level where we can then use it to select alternative pieces of code. After that it's cosmetic.

The simple, dumb #if blocks have the virtue is that they are not hostile to simple tooling, like Exuberant Ctags, Cscope, and whatnot. When we ask the editor to jump to the definition of ssize_t, it knows the three possible places where it is defined and serves them up.

This alternative is possible:

    #define PASTE3(a,b,c) a##b##c
    #define UINT_TYPE(bits) PASTE3(uint,bits,_t)
    #define INT_TYPE(bits,name) PASTE3(int,bits,_t)
    
    typedef UINT_TYPE(SIZE_T_BITS) usize_t;
    typedef INT_TYPE(SIZE_T_BITS) ssize_t;
I think in this form, there is a good chance the tools will grok the typedefs and index them, because we have not disguised the basic phrase structure.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: