Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>libstdc++ does define <code>__USE_MINGW_ANSI_STDIO</code> during build (<code>config/os/mingw32-w64/os_defines.h</code>), which will turn on the mingw <code>sprintf</code> wrapper. As @Michael Burr pointed out, these wrappers exist for C99/GNU99 compatibility.</p> <p>Your test does not define <code>__USE_MINGW_ANSI_STDIO</code>, hence you'll not get the wrapper with <code>stdio.h</code>. But since it was defined when building libstdc++, you'll get it with <code>cstdio</code>. If you however define it yourself before including <code>stdio.h</code>, you will get the wrapper again.</p> <p>So you do get in fact different implementations, and <code>cstdio std::sprintf</code> is not necessarily the same as <code>stdio.h sprintf</code>, at least not when it comes to mingw.</p> <p>Here is a test. First the source:</p> <pre><code>#ifdef USE_STDIO #include &lt;stdio.h&gt; #else #include &lt;cstdio&gt; using std::sprintf; #endif int main () { int i; for (i = 0; i &lt; 500000; i++){ char x[100]; sprintf(x, "x%dx%dx", i, i&lt;&lt;2); } } </code></pre> <p>Results:</p> <pre><code>$ g++ -o test_cstdio.exe test.cc $ g++ -o test_stdio.exe -DUSE_STDIO test.cc $ g++ -o test_stdio_wrap.exe -DUSE_STDIO -D__USE_MINGW_ANSI_STDIO test.cc $ for x in test_*.exe; do ( echo $x; objdump -d $x | grep sprintf; echo ); done test_cstdio.exe 40154a: e8 41 64 00 00 callq 407990 &lt;_Z7sprintfPcPKcz&gt; 0000000000402c40 &lt;__mingw_vsprintf&gt;: 0000000000407990 &lt;_Z7sprintfPcPKcz&gt;: 4079c8: e8 73 b2 ff ff callq 402c40 &lt;__mingw_vsprintf&gt; test_stdio.exe 40154a: e8 71 62 00 00 callq 4077c0 &lt;sprintf&gt; 00000000004077c0 &lt;sprintf&gt;: 4077c0: ff 25 6e 6c 00 00 jmpq *0x6c6e(%rip) # 40e434 &lt;__imp_sprintf&gt; test_stdio_wrap.exe 40154a: e8 41 64 00 00 callq 407990 &lt;_Z7sprintfPcPKcz&gt; 0000000000402c40 &lt;__mingw_vsprintf&gt;: 0000000000407990 &lt;_Z7sprintfPcPKcz&gt;: 4079c8: e8 73 b2 ff ff callq 402c40 &lt;__mingw_vsprintf&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload