a suspicious gcc warning

Stane Gruden staneg@rd.iskraemeco.si
Mon Feb 12 22:41:00 GMT 2001


Hi,

I have a question about one gcc warning. Why does the following 
code:

  typedef char TMy[4];
  void a(const TMy *b){}

  main(){
    TMy my;
    a(&my);  
  }

issue the next warning:

  'passing arg 1 of `a' from incompatible pointer type'?

I don't think this is correct. From the fact that the code (nothing
is 'const' here):

  typedef char TMy[4];
  void a(TMy *b){}

  main(){
    TMy my;
    a(&my);  
  }

or (implicit cast to 'const')

  typedef char TMy[4];
  void a(const TMy *b){}

  main(){
    TMy my;
    a((const TMy *)&my);  
  }

issues no warning, I suppose that the problem is in the word 'const'.
But as far as I know, giving a pointer to an object that is not
'const', to the function that has 'const' declared
in the argument is perfectly ok and should not produce the warning
above.

Any other opinions?

Stane Gruden, Kranj, Slovenia.
e-mail: staneg@rd.iskraemeco.si



More information about the Gcc mailing list