c - Discards qualifiers with memcpy -
why following code give me "discards qualifiers" warning?
double* const a[7]; memcpy(a,b,sizeof(double*)*7); the error i'm getting apple llvm version 6.1.0 (clang-602.0.53) (based on llvm 3.6.0svn)
warning: passing 'double *const [7]' parameter of type 'void *' discards qualifiers edit:
bonus question. why restrict keyword not work either?
double* restrict a[7]; memcpy(a,b,sizeof(double*)*7); edit 2:
i'm asking question, because want a const restrict pointer. can result code:
double* const restrict a[7] = {b[0], b[2], ... b[7]}; is stupid thing do?
you're trying pass const pointer function expects non const pointer.
edit:
more specifically, a array contents const pointers doubles. if attempted a[0] = b[0] (assuming b defined double *b[7] or similar) compiler error. results same if had const char a[7] , attempted a[0] = 'x'.
calling memcpy allows perform operation above otherwise prohibited.
in case of restrict, tells compiler memory pointed given pointer addressed given pointer. allows compiler perform optimizations.
from wikipedia:
it says lifetime of pointer, or value directly derived (such pointer + 1) used access object points.
since memcpy not expecting restrict * guarantee lost, why warning. in general, bypassing restrict can lead unpredictable behavior.
Comments
Post a Comment