diff mbox

[wwwdocs] Some stuff for porting to

Message ID 20150210180134.GL28333@redhat.com
State New
Headers show

Commit Message

Marek Polacek Feb. 10, 2015, 6:01 p.m. UTC
The following adds a few new notes.

Ok?


	Marek

Comments

Joseph Myers Feb. 10, 2015, 9:56 p.m. UTC | #1
On Tue, 10 Feb 2015, Marek Polacek wrote:

> +<p>Several new warnings have been added to the C front end.  One of the new
> +warnings is that GCC now warns about non-standard predefined macros with the
> +<code>-Wpedantic</code> option.  For instance:</p>
> +
> +<pre><code>
> +  void
> +  foo (void)
> +  {
> +    const char *s = __FUNCTION__;
> +  }
> +</code></pre>
> +
> +<pre>
> +<b>q.c:4:19:</b> <b style='color:magenta'>warning:</b> ISO C does not support <b>'__FUNCTION__'</b> predefined identifier [-Wpedantic]
> +  const char *s = __FUNCTION__;
> +                  <b style='color:lime'>^</b>
> +</pre>
> +
> +<p>The fix is either to use the standard predefined macro <code>__func__</code>
> +(since C99), or to use the <code>__extension__</code> keyword:<p/>

__FUNCTION__ and __func__ aren't macros (essentially they're built-in 
variables).
diff mbox

Patch

--- porting_to.html	10 Feb 2015 11:12:20 -0000	1.3
+++ porting_to.html	10 Feb 2015 17:58:52 -0000
@@ -251,6 +251,99 @@ 
                        <b style='color:lime'>^</b>
 </pre>
 
+<h4><code>__STDC_VERSION__</code> macro</h4>
+
+<p>In the C11 mode, the <code>__STDC_VERSION__</code> standard macro,
+introduced in C95, is now defined to <code>201112L</code>.  Typically,
+this macro is used as in the following:</p>
+
+<pre><code>
+  #if !defined __STDC_VERSION__ || __STDC_VERSION__ &lt; 199901L
+    /* ... */
+  #else
+  # include &lt;stdint.h&gt;
+  #endif
+</code></pre>
+
+<p>You can check the macro using <code>gcc -dM -E -std=gnu11 - &lt; /dev/null | grep STDC_VER</code>.</p>
+
+<h4>Different meaning of the <code>%a *scanf</code> modifier</h4>
+
+<p>The GNU C library supports dynamic allocation via the <code>%a</code>
+modifier.  But in C99, the <code>%a</code> modifier is a synonym for
+<code>%f</code> (float), so the compiler expects an argument of type
+<code>float *</code>.  This in combination with the <code>-Wformat</code>
+warning option may result in additional warnings:</p>
+
+<pre><code>
+  #include &lt;stdio.h&gt;
+
+  int
+  main (void)
+  {
+    char *s;
+    scanf ("%as", &s);
+  }
+</code></pre>
+
+<pre>
+<b>q.c:7:10:</b> <b style='color:magenta'>warning:</b> format <b>'%a'</b> expects argument of type <b>'float *'</b>, but argument 2 has type <b>'char **'</b> [-Wformat=]
+  scanf ("%as", &s);
+         <b style='color:lime'>^</b>
+</pre>
+
+<p>The fix is to use the <code>%m</code> modifier instead, specified by
+POSIX.1-2008.</p>
+
+<h3>New warnings</h3>
+
+<p>Several new warnings have been added to the C front end.  One of the new
+warnings is that GCC now warns about non-standard predefined macros with the
+<code>-Wpedantic</code> option.  For instance:</p>
+
+<pre><code>
+  void
+  foo (void)
+  {
+    const char *s = __FUNCTION__;
+  }
+</code></pre>
+
+<pre>
+<b>q.c:4:19:</b> <b style='color:magenta'>warning:</b> ISO C does not support <b>'__FUNCTION__'</b> predefined identifier [-Wpedantic]
+  const char *s = __FUNCTION__;
+                  <b style='color:lime'>^</b>
+</pre>
+
+<p>The fix is either to use the standard predefined macro <code>__func__</code>
+(since C99), or to use the <code>__extension__</code> keyword:<p/>
+
+<pre><code>
+  const char *s = __extension__ __FUNCTION__;
+</code></pre>
+
+<h2>C++ language issues</h2>
+
+<h3>Converting <code>std::nullptr_t</code> to <code>bool</code></h3>
+
+<p>Converting <code>std::nullptr_t</code> to <code>bool</code> in the C++11
+mode now requires direct-initialization.  This has been changed in
+<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1423">DR 1423</a>.
+As a consequence, the following is invalid:</p>
+
+<pre><code>
+  bool b = nullptr;
+</code></pre>
+
+<p>but the following is valid:</p>
+
+<pre><code>
+  bool b(nullptr);
+</code></pre>
+
+It is recommended to use <code>true</code>, resp. <code>false</code> keywords
+in such cases.
+
 <h3>Links</h3>
 
 <p>