ANSI-C: maximum number of characters printing a decimal int

前端 未结 8 1668
醉梦人生
醉梦人生 2021-02-19 10:17

I\'d like to know if it is an easy way of determining the maximum number of characters to print a decimal int.

I know contains

8条回答
  •  失恋的感觉
    2021-02-19 10:37

    Here's the C version:

    #include 
    
    #define xstr(s) str(s)
    #define str(s) #s
    #define INT_STR_MAX sizeof(xstr(INT_MAX))
    
    char buffer[INT_STR_MAX];
    

    Then:

    $ gcc -E -o str.cpp str.c
    $ grep buffer str.cpp
    char buffer[sizeof("2147483647")];
    
    $ gcc -S -o str.S str.c
    $ grep buffer str.S
        .comm   buffer,11,1
    

提交回复
热议问题