Immutable cannot be casted to const when using pointers

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 8 14:53:58 PDT 2014


On Tue, 08 Apr 2014 17:05:09 -0400, Jeroen Bollen <jbinero at gmail.com>  
wrote:

> For some reason this code doesn't work...
>
> module app;
>
> void main() {
> 	immutable char var = 'a';
> 	immutable(char)* varPtr = &var;
> 	test(&varPtr);
> }
>
> void test(immutable(char)** param) {
> 	test2(param);
> }
>
> void test2(const(char)** test2) {
> 	
> }
>

...

> Is this a bug? I'm using DMD.

No, it's intended. If that was allowed, you could inadvertently overwrite  
immutable data without a cast.

The rule of thumb is, 2 or more references deep does not implicitly  
convert. One reference deep is OK.

-Steve


More information about the Digitalmars-d mailing list