Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Table of "safe" methods to suppress "unused parameter" warnings?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="mathog" data-source="post: 5151576"><p>Here is a small example program to test these methods on</p><p>various compilers. The results I found follow the program.</p><p>(I don't have access to all that many compilers, and some of them are</p><p>very old.)</p><p></p><p>---cut here -- test_unused.c --</p><p>#include <stdlib.h></p><p>#include <stdio.h></p><p></p><p>#ifdef UNUSED</p><p>#elif defined(__GNUC__)</p><p># define UNUSED(x) UNUSED_ ## x __attribute__((unused))</p><p>#elif defined(__LCLINT__)</p><p># define UNUSED(x) /*@unused@*/ x</p><p>#else</p><p># define UNUSED(x) x</p><p>#endif</p><p></p><p></p><p>void method1(int x){</p><p>(void) x;</p><p>printf("method 1\n");</p><p>}</p><p></p><p>void method2(int x){</p><p>x = x;</p><p>printf("method 2\n");</p><p>}</p><p></p><p>void method3(int x){</p><p>*(volatile typeof(x) *) &(x) = (x);</p><p>printf("method 3\n");</p><p>}</p><p></p><p>void method4(int x){</p><p>if(x){};</p><p>printf("method 4\n");</p><p>}</p><p></p><p>void method5(int UNUSED(x)){</p><p>printf("method 5\n");</p><p>}</p><p></p><p>int main(void){</p><p>method1(1);</p><p>method2(1);</p><p>method3(1);</p><p>method4(1);</p><p>method5(1);</p><p>exit(EXIT_SUCCESS);</p><p>}</p><p>---cut here ----</p><p></p><p>Results:</p><p></p><p>(gcc 4.6.3 and 4.7.2 tested, they did the same thing)</p><p>gcc -Wall -Wextra --std=c99 -o test_unused test_unused.c</p><p>warns:</p><p>test_unused.c: In function 'method3':</p><p>test_unused.c:24:4: error: unknown type name 'typeof'</p><p>test_unused.c:24:22: error: expected ')' before 'x'</p><p>test_unused.c:24:25: error: expected ')' before '*' token</p><p></p><p>gcc -Wall -Wextra -o test_unused test_unused.c</p><p>no warnings</p><p></p><p>(Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on</p><p>LLVM 3.0))</p><p>clang -Wall -o test_unused test_unused.c</p><p>warns:</p><p>test_unused.c:20:6: warning: explicitly assigning a variable</p><p>of type 'int' to itself [-Wself-assign]</p><p>x = x;</p><p>~ ^ ~</p><p></p><p>(A very old version of the intel linux compiler == 9.0)</p><p>iccbin -Wall -std=c99 -gcc-version=340 -i-static \</p><p>-o test_unused test_unused.c</p><p>warns about "external definition with no prior declaration" for all</p><p>of the functions, but did not warn about anything else.</p><p></p><p>(A very old version of the Sun Forte Developer 7.0 C 5.4</p><p>on an equally old Sparc)</p><p>cc -o test_unused test_unused.c</p><p>warns:</p><p>"test_unused.c", line 25: warning: no explicit type given</p><p>"test_unused.c", line 25: syntax error before or at: typeof</p><p>"test_unused.c", line 29: type specifier can not be used as array size</p><p>expression qualifier</p><p>"test_unused.c", line 29: warning: no explicit type given</p><p>"test_unused.c", line 29: cannot recover from previous errors</p><p></p><p>And that's all the compilers I have to test.</p><p></p><p></p><p>Regards,</p><p></p><p>David Mathog</p></blockquote><p></p>
[QUOTE="mathog, post: 5151576"] Here is a small example program to test these methods on various compilers. The results I found follow the program. (I don't have access to all that many compilers, and some of them are very old.) ---cut here -- test_unused.c -- #include <stdlib.h> #include <stdio.h> #ifdef UNUSED #elif defined(__GNUC__) # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) #elif defined(__LCLINT__) # define UNUSED(x) /*@unused@*/ x #else # define UNUSED(x) x #endif void method1(int x){ (void) x; printf("method 1\n"); } void method2(int x){ x = x; printf("method 2\n"); } void method3(int x){ *(volatile typeof(x) *) &(x) = (x); printf("method 3\n"); } void method4(int x){ if(x){}; printf("method 4\n"); } void method5(int UNUSED(x)){ printf("method 5\n"); } int main(void){ method1(1); method2(1); method3(1); method4(1); method5(1); exit(EXIT_SUCCESS); } ---cut here ---- Results: (gcc 4.6.3 and 4.7.2 tested, they did the same thing) gcc -Wall -Wextra --std=c99 -o test_unused test_unused.c warns: test_unused.c: In function 'method3': test_unused.c:24:4: error: unknown type name 'typeof' test_unused.c:24:22: error: expected ')' before 'x' test_unused.c:24:25: error: expected ')' before '*' token gcc -Wall -Wextra -o test_unused test_unused.c no warnings (Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0)) clang -Wall -o test_unused test_unused.c warns: test_unused.c:20:6: warning: explicitly assigning a variable of type 'int' to itself [-Wself-assign] x = x; ~ ^ ~ (A very old version of the intel linux compiler == 9.0) iccbin -Wall -std=c99 -gcc-version=340 -i-static \ -o test_unused test_unused.c warns about "external definition with no prior declaration" for all of the functions, but did not warn about anything else. (A very old version of the Sun Forte Developer 7.0 C 5.4 on an equally old Sparc) cc -o test_unused test_unused.c warns: "test_unused.c", line 25: warning: no explicit type given "test_unused.c", line 25: syntax error before or at: typeof "test_unused.c", line 29: type specifier can not be used as array size expression qualifier "test_unused.c", line 29: warning: no explicit type given "test_unused.c", line 29: cannot recover from previous errors And that's all the compilers I have to test. Regards, David Mathog [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Table of "safe" methods to suppress "unused parameter" warnings?
Top