Why doesn't a cast quell a warning?

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

 



I see this in my build: 

../../gcc/cobol/cdf.y:279:19: warning: ignoring return value of ?int
asprintf(char**, const char*, ...)?, declared with attribute
warn_unused_result [-Wunused-result] 

279 |     (void)asprintf (&display_msg, "%s %s", p, $2);

The point of the cast is to signal to the compiler that the programmer
has determined that in this case there's no need for the returned value.
I'm not sure there's a better way, except that that way doesn't work.  

gcc is itself rife with cases like this, except not accounted for,
e.g., 

../../gcc/gcc.cc:7757:13: warning: ignoring return value of ?ssize_t
write(int, const void*, size_t)?, declared with attribute
warn_unused_result [-Wunused-result] 

7757 |       write (fd, new_argv[i], strlen (new_argv[i]));

I'm not myself convinced that  -Wunused-result is all that useful.
But, if it's used, shouldn't it be possible to quell the warning
without wrapping the line in pragmas?  

--jkl




[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