NO

Author Topic: Compiler's weird type check for pointers: bug or intended?  (Read 3166 times)

dlOuOlb

  • Guest
Compiler's weird type check for pointers: bug or intended?
« 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?
« Last Edit: July 10, 2019, 06:53:09 AM by dlOuOlb »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Compiler's weird type check for pointers: bug or intended?
« Reply #1 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]
May the source be with you

dlOuOlb

  • Guest
Re: Compiler's weird type check for pointers: bug or intended?
« Reply #2 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
So it is not a compiler-specific issue, but the language's one.

Thanks.