Question re specific implicit type coercion
Don Allen
donaldcallen at gmail.com
Mon Oct 18 15:04:11 UTC 2021
I am calling a C function, described in D as
extern (C) GtkWidget* gtk_menu_item_new_with_label
(immutable(char)*);
I call it like this
accounts_menu_item = gtk_menu_item_new_with_label("New account
(Ctrl-n)");
The type of the string literal in the call is immutable(char)[].
The type of the parameter is a pointer to immutable characters.
This setup works.
My question is about the documentation vs. what is really going
on here.
Section 12.17 of the Language Reference does not indicate any
circumstance in which a dynamic array, which the literal is, is
implicitly coerced to a pointer. I realize that this is a special
case -- the callee is a C function -- that might not be covered
by this section. So I looked at Section 32.3, Chapter 32 being
"Interfacing to C". 32.3 contains a table of correspondences
between D and C types. The entry for the D type T[] indicates no
correspondence in C.
So at least my reading of the documentation suggests that my code
should not compile. And yet it does and works, which leads me to
believe there is a documentation error that ought to be reported.
Before doing so, I decided to send this message so those of you
who know D a lot better than I do can tell me what I've missed or
gotten wrong, if that is the case.
Thanks --
/Don
More information about the Digitalmars-d-learn
mailing list