Stefan Glienke 2002 Posted March 24, 2021 (edited) function (const arr: TArray<T>): RecWithTwoFields (Pointer, Integer) Bonus: inlining that function looks like this - go go eax, you got it eventually! Edited March 24, 2021 by Stefan Glienke 1 1 1 2 2 Share this post Link to post
Dalija Prasnikar 1396 Posted March 24, 2021 19 hours ago, Stefan Glienke said: Bonus: inlining that function looks like this - go go eax, you got it eventually! That is useful if you get paid by the LOC compiler generates- 3 Share this post Link to post
Stefan Glienke 2002 Posted March 31, 2021 Inspired by that other thread: procedure TypeSafeMyAss(i: Cardinal); begin end; var i: Integer; begin i := -1; {$RANGECHECKS ON} TypeSafeMyAss(i); end. 1 Share this post Link to post
Leif Uneus 43 Posted March 31, 2021 27 minutes ago, Stefan Glienke said: Inspired by that other thread: procedure TypeSafeMyAss(i: Cardinal); begin end; var i: Integer; begin i := -1; {$RANGECHECKS ON} TypeSafeMyAss(i); end. I don't know what you mean. For sure it gives a range check error. Share this post Link to post
Stefan Glienke 2002 Posted March 31, 2021 (edited) 16 minutes ago, Leif Uneus said: I don't know what you mean. For sure it gives a range check error. Exactly - at runtime. Warning would be nice, don't you think? Edit: to be clear not because I put the -1 there which will for sure blow up but because Integer->Cardinal will blow up for 50% of the value range. We have W1023 and W1024 when comparing or combining, but assignment/parameter passing blows up at runtime... eventually, some day. Edited March 31, 2021 by Stefan Glienke 2 Share this post Link to post
Leif Uneus 43 Posted March 31, 2021 9 minutes ago, Stefan Glienke said: Exactly - at runtime. Warning would be nice, don't you think? Ok, yes a warning would be expected! Share this post Link to post
Stefan Glienke 2002 Posted April 1, 2021 Inspired by RSP-28311: {$APPTYPE CONSOLE} uses TypInfo; type generic = record class procedure test<T>(const value : T); static; end; class procedure generic.test<T>(const value: T); begin Writeln(GetTypeName(TypeInfo(T))); end; procedure test(a: Int32); overload; begin Writeln('Int32'); end; procedure test(a: Int64); overload; begin Writeln('Int64'); end; procedure test(a, b: Int32); overload; begin Writeln('Int32'); end; procedure test(a, b: Int64); overload; begin Writeln('Int64'); end; const one = Int64(1); two = Int64(MaxInt); three = Int64(MaxInt)+1; four: Int64 = 1; begin generic.test(one); // Int64 generic.test(two); // Int64 generic.test(three); // Int64 generic.test(four); // Int64 test(one); // Int64 test(two); // Int64 test(three); // Int64 test(four); // Int64 test(one, 1); // Int32 ?! test(two, 1); // Int32 test(three, 1); // Int64 test(four, 1); // Int64 test(one, Int64(1)); // Int64 test(Int64(1), 1); // Int32 ?! end. 1 Share this post Link to post
Attila Kovacs 629 Posted April 1, 2021 (edited) restart, mom if I add procedure test(a: Int64; b: Int32); overload; begin Writeln('Int64/Int32'); end; everything is ok again. Why should the compiler decide for Int64 if it fits into Int32? We know that the type cast in the const declaration is just some placeholder. Edited April 1, 2021 by Attila Kovacs Share this post Link to post
Stefan Glienke 2002 Posted April 1, 2021 (edited) 9 minutes ago, Attila Kovacs said: We know that the type cast in the const declaration is just some placeholder. Which is not what the documentation says: Quote const MyNumber = Int64(17); declares a constant called MyNumber, of type Int64, that returns the integer 17. Edited April 1, 2021 by Stefan Glienke 1 Share this post Link to post
Attila Kovacs 629 Posted April 1, 2021 @Stefan Glienke yop, I've seen that, still... anyway reload my comment again 🙂 Share this post Link to post
Attila Kovacs 629 Posted April 1, 2021 (edited) 11 minutes ago, Stefan Glienke said: Which is not what the documentation says: Ahh, I see. @Stefan Glienke So you mean, it should not compile if the integer size and signedness does not match to any of the method declarations? Or should it bring warnings? I'd love to see those messages, could be interesting! Edited April 1, 2021 by Attila Kovacs Share this post Link to post