why does __builtin_types_compatible_p work this way?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(Original thread, and test program, can be found here at http://permalink.gmane.org/gmane.comp.gcc.help/26289)

A few days ago, Kevin posted an interesting problem, whose ultimate solution I find rather confusing... Here's the results of __builtin_types_compatible_p on some various types; I'm hoping someone that knows gcc's internals can comment?

> char*, char* => true
> char*, const char* => false

The doc says that qualifiers are ignored, but in this case that isn't happening? (However, we WANT this behavior, so this is a complaint against the doc, not the code generation!)

> char[], char* => false

Why are these not compatible?

> char[], const char[] => true

Ok, here the qualifier is being ignored?

> typeof("hello"), char* => false
> typeof("hello"), char[] => true
> typeof("hello"), const char* => false
> typeof("hello"), const char[] => true

This seems... odd. Given the above I can understand how the 'const' is getting lost, but this seems less helpful than it could be.

> typeof(&(*"hello")), char* => true
> typeof(&(*"hello")), char[] => false
> typeof(&(*"hello")), const char* => false
> typeof(&(*"hello")), const char[] => false

I think I understand why gcc ate the 'const' here, but it's still a little scary :-).

> typeof(&(("hello")[0])), char* => false
> typeof(&(("hello")[0])), char[] => false
> typeof(&(("hello")[0])), const char* => true
> typeof(&(("hello")[0])), const char[] => false

...and we finally arrive at a useful incantation that turns pointer-or-array into pointer without losing the qualifier. But why was this necessary?

--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
When in doubt, give it a good swift kick.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux