any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Tue Nov 27 01:14:37 PST 2007


Derek Parnell wrote:
> On Mon, 26 Nov 2007 21:24:13 -0800, Walter Bright wrote:
> 
>> I'm not sure why one would need protection against changing the bitmap 
>> pointer. GammaAdjust should just take a byte[], not a ref byte[].
> 
>  byte[] bitmap;
>  bitmap = LoadBitMapFromFile("worldroadmap.bmp");
>  GammaAdjust(bitmap, 0.20);
>  Render(device, bitmap);
> 
> If the 'GammaAdjust' routine changed the pointer then 'Render' routine
> would not display the adjusted bitmap. 
> 
> So I would like to tell the compiler that 'GammaAdjust' is not allowed to
> change the pointer and thus if (at compile time) it does so the compiler
> should tell me of the error.

Change GammaAdjust from (ref byte[] bitmap) to (byte[] bitmap), and it 
cannot change the caller's copy.



More information about the Digitalmars-d mailing list