Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's usually better for your code to describe as accurately as possible what's going on. You're getting this warning because the <code>const</code> in <code>const int foo();</code> is basically meaningless. The API only seems clearer if you don't know what the <code>const</code> keyword means. Don't overload meaning like that; <code>static</code> is bad enough as it is, and there's no reason to add the potential for more confusion.</p> <p><code>const char *</code> means something different than <code>const int</code> does, which is why your tool doesn't complain about it. The former is a pointer to a constant string, meaning any code calling the function returning that type shouldn't try to modify the contents of the string (it might be in ROM for example). In the latter case, the system has no way to enforce that you not make changes to the returned <code>int</code>, so the qualifier is meaningless. A closer parallel to the return types would be:</p> <pre><code>const int foo(); char * const foo2(); </code></pre> <p>which will both cause your static analysis to give the warning - adding a const qualifier to a return value is a meaningless operation. It only makes sense when you have a a reference parameter (or return type), like your <code>const char *</code> example.</p> <p>In fact, I just made a little test program, and GCC even explicitly warns about this problem:</p> <pre><code>test.c:6: warning: type qualifiers ignored on function return type </code></pre> <p>So it's not just your static analysis program that's complaining.</p>
 

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