Pelles C forum

Pelles C => General discussions => Topic started by: dlOuOlb on July 10, 2019, 06:50:36 am

Title: Compiler's weird type check for pointers: bug or intended?
Post by: dlOuOlb on July 10, 2019, 06:50:36 am
The compiler does not allow to assign from a variable pointer to a constant pointer, like following:
Code: [Select]
int main(void)
{
    char *Foo="Hello.";
    const char *Bar;
    const char **Baz;

    Bar=Foo;
    Baz=&Bar;   //no warning, no error

    Baz=&Foo;   //error #2168

    return 0;
}
error #2168: Operands of '=' have incompatible types 'const char * *' and 'char * *'.

I know that Pelles C is strict at type check, but is it intended even for this case?
Title: Re: Compiler's weird type check for pointers: bug or intended?
Post by: TimoVJL on July 10, 2019, 10:19:27 am
cast it
Code: [Select]
...
Baz=(const char**)&Foo;
...
clang:
Code: [Select]
warning: assigning to 'const char **' from 'char **' discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
Title: Re: Compiler's weird type check for pointers: bug or intended?
Post by: dlOuOlb on July 11, 2019, 01:46:57 am
I searched the clang's warning message in your answer, and found this answer:
http://stackoverflow.com/questions/5055655/double-pointer-const-correctness-warnings-in-c (http://stackoverflow.com/questions/5055655/double-pointer-const-correctness-warnings-in-c)
So it is not a compiler-specific issue, but the language's one.

Thanks.