Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

And if you don't need string constant, but just a string, then you can use the following (I'm not sure about portability though):

    #include <stdio.h>

    #define VERSION_INT 3209

    #if VERSION_INT < 100
    #error VERSION_INT less than 100
    #elif VERSION_INT < 1000
    #define VERSION_STR (char[]){VERSION_INT/100+'0','.',(VERSION_INT%100)/10+'0',(VERSION_INT%10)+'0',0
    #elif VERSION_INT < 10000
    #define VERSION_STR (char[]){VERSION_INT/1000+'0',(VERSION_INT%1000)/100+'0','.',(VERSION_INT%100)/1
    #endif

    int main(void)
    {
        printf("%d\n", VERSION_INT);
        printf("%s\n", VERSION_STR);
        return 0;
    }
Output:

    3209
    32.09



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

Search: