archives.c: In function ‘fd_writeback_wait’:
archives.c:121:21: warning: passing argument 1 of ‘aio_suspend’ from incompatible pointer type [-Wincompatible-pointer-types]
r = aio_suspend(&cb, 1, NULL);
^~~
In file included from ../lib/dpkg/fsys.h:28,
from ../lib/dpkg/triglib.h:28,
from archives.c:57:
/usr/include/aio.h:168:51: note: expected ‘const struct aiocb * const*’ but argument is of type ‘struct aiocb **’
extern int aio_suspend (const struct aiocb *const __list[], int __nent,
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
Explanations:
- Why isn't it legal to convert "pointer to pointer to non-const" to a "pointer to pointer to const"
- ... or look at the Related questions list on the right hand side of the screen, and take your pick :-).
I think there is no way to avoid this warning, without writing a dangerous type cast to change the const qualifiers, or suppressing the whole category of warnings.
Apparently C++ does better here. It also has const_cast
for clearer casting, which makes sure that you are only changing const qualifiers.
In other words, POSIX defining aio_suspend() to use const
like this is arguably rather dangerous.
Have I interpreted this correctly?
If I am wrong, then how can I avoid this warning, but still have the compiler check that I am only casting const
qualifiers, and not casting to a completely incompatible type?
I suspect if there are methods, they would not be ones that I would want to use in practice, but I am curious.
The current code I am working on does not explicitly document a required compiler version.
I would be interested in techniques that work in standard C versions. I would be interested to hear about GCC extensions. Comments about whether it is recommended or dis-recommended to define function parameters like this are also welcome.
Readers are reminded that C and C++ are different, and not 100% compatible languages. I acknowledge that switching code bases to C++ could probably provide a solution, but I do not think that solution would be very useful to me. Thank you.