News for hackers. Stuff that matters.
Re:Android Project Changeset 4f8b683: libc/memset.c by queensnake on Tuesday May 25, 2010 @08:50PM (#1379179)
| The unused parameter warning is one of the biggest offenders in this area. And if you have a hundred warnings for unused parameters, which ones do you pay attention to?

Well, so then you're exposed to this error. Do:

    void foo(int x)
    {
       (void)x;
    }
to silence unused parameter warnings.
Re:Android Project Changeset 4f8b683: libc/memset.c by tptacek on Tuesday May 25, 2010 @09:02PM (#1379202)
Go look at Google code search, which includes vast quantities of code written by professional teams and (often later) open sourced. Very little of it casts expressions to (void). When I started at Arbor, I got rid of all the (void) casts. What an eyesore.

Very little C code is const-correct either. Most of the C devs I know make fun of const-correctness.

Re:Android Project Changeset 4f8b683: libc/memset.c by humbledrone on Tuesday May 25, 2010 @09:31PM (#1379245)
| What an eyesore.

It's only an eyesore if you don't acknowledge the benefits that strict warnings can bring to the table.

| Most of the C devs I know make fun of const-correctness.

I for one don't mind putting in a tiny bit of upfront effort so that my compiler can double-check my work. Do the C devs you know also make fun of assert?

Re:Android Project Changeset 4f8b683: libc/memset.c by tptacek on Tuesday May 25, 2010 @09:34PM (#1379249)
I don't acknowledge the benefits of casting things to (void). Therefore: definitely an eyesore.

And, no. Nobody makes fun of assert. Which rather makes my point for me.

Re:Android Project Changeset 4f8b683: libc/memset.c by ehnus on Tuesday May 25, 2010 @10:57PM (#1379379)
If assertions disappear in certain optimized builds then what do you do, or recommend, to deal with warnings related to unused parameters or values if you don't believe that casting to void has value?
Re:Android Project Changeset 4f8b683: libc/memset.c by tptacek on Wednesday May 26, 2010 @10:49AM (#1380396)
I don't understand how the question you ask even follows from the premise you forwarded. The fact that memset is probably always dead code here is why it's not really a bug. The fact that warnings about unused return values are useless 100-1000 times for every time they're potentially useful is why I don't litter my code with pointless casts.
Re:Android Project Changeset 4f8b683: libc/memset.c by scott_s on Tuesday May 25, 2010 @11:12PM (#1379408)
As I pointed out above, in gcc you can explicitly mark variables as potentially unused.
Re:Android Project Changeset 4f8b683: libc/memset.c by ehnus on Tuesday May 25, 2010 @11:43PM (#1379444)
And what do you suggest for MSVC, which doesn't support attribute unused or have any comparable declspecs?
Re:Android Project Changeset 4f8b683: libc/memset.c by scott_s on Wednesday May 26, 2010 @01:10AM (#1379579)
If what you say is true, then you have to either put up with the warnings, compile at a level that doesn't have the warnings, or figure out a hack around them - I don't like any of those options.

I'm not as dogmatic as some others are in the thread. I just think it's a good idea to be warned when a variable is unused, enough that I'll mark my very few that might be #ifdef'ed out. If you're using a compiler that doesn't let you mark variables as such... well that sucks. You do what you can.

Re:Android Project Changeset 4f8b683: libc/memset.c by josephruscio on Wednesday May 26, 2010 @12:24AM (#1379510)
Your compiler may offer a more formal way to indicate that it's acceptable for a parameter to be unused. In gcc it's an attribute:

int foobar(int foo, int bar __attribute__((unused))) { /* Code that does not use bar */}

Re:Android Project Changeset 4f8b683: libc/memset.c by scott_s on Tuesday May 25, 2010 @11:06PM (#1379397)
If you're using gcc, you can say __attribute__((unused)): http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Variable-Attribu...
Re:Android Project Changeset 4f8b683: libc/memset.c by s3graham on Tuesday May 25, 2010 @09:16PM (#1379215)
(void)x does not work on all compilers to silence the warning. gcc + cl != C.