Menu

%lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long}'.

chrisfetz
2020-04-27
2020-04-27
  • chrisfetz

    chrisfetz - 2020-04-27

    size idx( 0 );
    char string[ 256 ] = "";
    sprintf( string, "%lu", idx );
    with cppcheck v1.90 results in:
    (cppcheck portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long}'.
    where is the mistake?

    Best regards,
    Christoph

     
  • Daniel Marjamäki

    it's by intention.. your code is not portable. Use a format string that requires 'size_t'.

    Not sure but I think %zu might be better.

     
  • chrisfetz

    chrisfetz - 2020-04-27

    Ah, ok, I was a little confused by requires 'unsigned long' but..... 'aka unsigned long'...
    Thank you very much!
    In my case, it's %Iu (capital i instead of l).

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.