#265 Bug in <cstdio> regarding sprintf

v1.0 (example)
pending-remind
nobody
None
5
2012-02-26
2012-01-06
Cary R.
No

The following code prints an error when compiling on Cygwin using the i686-w64-mingw320g++ compiler and the -Wall flag. If <stdio.h> is used instead of <cstdio> then no warnings is printed.

#include <inttypes.h>
#include <cstdio>
// Using <stdio.h> does not complain.

int main()
{
uint64_t uval=0;
int64_t val=0;
char buf[100];
sprintf(buf, "%I64u", uval);
sprintf(buf, "%I64o", uval);
sprintf(buf, "%I64x", uval);
sprintf(buf, "%I64d", val);
return 0;
}

Discussion

  • Jonathan Yong

    Jonathan Yong - 2012-01-06

    This is due the decision use C99 print specifiers for C++, so std::cout and friends can print 64bit characters. There isn't a clean way to fix this problem yet.

     
  • Kai Tietz

    Kai Tietz - 2012-01-19

    Hmm, yes isn't really a bug. At least not in hard term.
    Problem here is that libstdc++ requires that posix-printf/scanf routines are active by default. This means that none-underscored version of printf/scanf family are using POSIX semantics.
    Sadly there is no _sprintf function provided by msvcrt. But maybe we should provde it by our import-library as forwarder to msvcrt's sprintf (same might apply to other printf/scanf-routines too)

     
  • Kai Tietz

    Kai Tietz - 2012-02-26

    The printf functions are for libstdc++ for 4.7 always POSIX print routines now by default. This is caused by the strict dependency of libstdc++ to POSIX printf/scanf routines.

     
  • Kai Tietz

    Kai Tietz - 2012-02-26
    • status: open --> pending-remind
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks