Passing an in parameter and aliasing

Bill Baxter dnewsgroup at billbaxter.com
Fri May 25 15:38:01 PDT 2007


renoX wrote:
> Bill Baxter a écrit :

>> The thing with this is it may catch the error but it doesn't help the 
>> compiler generate more optimized code.  The C99 'restrict' keyword 
>> does, though.  I suppose the compiler could be smart enough to deduce 
>> 'restrict' semantics are in effect from the assert message above.  
>> That would be pretty neat.
> 
> Well, if I understood correctly Jarrett Billingsley's answer, the 
> semantic on 'in' is the same as 'restrict': the fastest as the compiler 
> will be free to optimize but the most fragile from programmers point of 
> view because if you violate the restrict restriction the result is 
> unpredictable (no bug, a bug depending on optimization flags, fun!)
> 
> Sure, it'd be nice if the compiler was able to do this kind of 
> optimization without the in|restrict hint but this is hard.

The 'in' parameter type does nothing currently.  Leaving it off is the 
same as putting it in.  So I don't believe it acts like 'restrict'.  I 
certainly don't remember reading anywhere in the spec that D assumes all 
'in' array parameters are unaliased.  That would be a big break from 
C/C++ if it were so, so I think the spec would go out of its way to 
point out the difference.

--bb



More information about the Digitalmars-d mailing list