Outside array bounds
Timoses
timosesu at gmail.com
Sat Jul 7 11:22:38 UTC 2018
On Saturday, 7 July 2018 at 08:35:27 UTC, Alex wrote:
> On Saturday, 7 July 2018 at 08:24:21 UTC, Timoses wrote:
>> Interesting.. Looks like the compiler does some boundschecking
>> during compile time. You could circumvent this:
>>
>>
>> void process(T ...)(string ID, T args) {
>> if (ID == "I1") { writeln(args.length, "\t", args[0]);
>> }
>> static if (T.length > 1) // only add below code if
>> cond. true
>> if (ID == "I2") { writeln(args.length, "\t",
>> args[1]);}
>> }
>>
>> Oddly, when leaving out the "static if" statement, the error
>> still occurs when compiling with "-release" or with
>> "-boundscheck=off"... I thought those would/should disable
>> bounds checking at compile time???
>
> Nonono ))
>
> In this case, the bound checks are like interface checking...
> or like type checking... As there are different processes
> instantiations for different number of args.
> I hope this can't be turned off so easily... ))))
Aw, got it. So args is actually a tuple type where accessing
beyond the defined tuple (T) is invalid?
auto a = [1, 2, 4];
// works
pragma(msg, typeof(a[3]));
auto t = tuple(3, 4, 5.3);
// ERROR:
// pragma(msg, typeof(t[3]));
More information about the Digitalmars-d-learn
mailing list