Hello,
why differentiates the compiler in assigning a "pointer to const" an adress directly or via a function call?
void test (const uint16_t *cpui16) { if (*cpui16 == 17) return; } void test1(void) { uint16_t ui16 = 9U; uint16_t *p = &ui16; const uint16_t *cp = &ui16; //warning C102: test(&ui16); //no warning test(p); test(cp); }
And why marks the compiler a warning and the manual an error? Compiler warning C102: '=': different const/volatile qualifiers
Manual *** Error C102
operator: Different const/volatile Qualifiers
I cannnot imagine a potential problem with
const uint16_t *cp = &ui16;
Can anybody give me a hint?
Best regards Jürgen
Oh yes, I think I got the point.
I know the qualifiers 'const' and 'volatile' and I tried to tell the compiler, that I don't want to change the value of the variable ui16 which the pointer cp dereferences via this pointer (as lint suggested).
But what I really did was telling the compiler that pc dereferences a variable that would not change ever. And that is a difference as I see now.
Thanks again for your kind effort although I don't see how I can satisfy lint (which suggested to declare cp as pointing to const) and the compiler (which says the variable cp dereferences isn't really const)