Re: Werror

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/02/2016 09:55, manojmaybe wrote:

> I have used the test variable as:
>
> int statistics()
> {
>     test = &(stud);
>     assert(test->total != 0);
>     return true;
> }
> 
> then get error: variable 'test' set but not used [-Werror=unused-but-set-variable]

Note: you're more likely to get help when you provide a complete
example, i.e. one that others can compile and test locally.

#include <assert.h>
struct obj { int total; } stud;
int statistics()
{
    struct obj *test;
    test = &stud;
    assert(test->total != 0);
    return 1;
}

$ gcc -Wall -Wextra -Werror -c assert.c

No errors there.

$ gcc -DNDEBUG -Wall -Wextra -Werror -c assert.c
assert.c: In function 'statistics':
assert.c:5:17: error: variable 'test' set but not used [-Werror=unused-but-set-variable]
     struct obj *test;
                 ^
cc1: all warnings being treated as errors


Did you check whether NDEBUG is set? (It turns assert() into a NOP.)
http://man7.org/linux/man-pages/man3/assert.3.html

Regards.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux