Casting away const
Mafi
mafi at example.org
Mon Aug 9 08:58:17 PDT 2010
Am 09.08.2010 17:31, schrieb bearophile:
> Steven Schveighoffer:
>> But an extern(C) function does not have to be written in C :)
>
> You are right. But that function written in an arbitrary language has to follow the C interface rules and limitations, and among those there is no way to define a variable to be const(char)*.
>
> So in that line of code you are writing something that can't be enforced. Generally D design refuses features that the compiler is unable to verify. So I think an enhancement request to disallow that is good here. An extern(C) call has to specify only things that are understood by the C interface.
>
> On the other hand in C you have const, but its semantics is different. Uhm...
>
> Bye,
> bearophile
I think, that isn't a good idea. I mean const-ness a compile time thing
so the c abi has no problem with it. What's wrong when I define a
extern(c) bool thinkeAboutMyInt(const int* x) {
....
}
I want to inform the D typesystem that I'm not going to change the int
but I need a pointer because the adress is important. I want this
function to be also callable outside D (eg C).
Mafi
More information about the Digitalmars-d-learn
mailing list