Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-11

type IntegerList

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Juha Manninen
to Alexey

On Mon, Nov 13, 2017 at 7:58 PM, Alexey via Lazarus <

Show quoted text 9 lines
wrote: Thanks for this new list. Diff like - Result:=integer(PtrUInt(FCols[aCol])) + Result:=FCols[aCol] shows it's useful. It supports Longint or PtrInt or PtrUInt? Or i need another list for PtrInt?

It supports Integer which means Longint.
You need another list for PtrInt but it is very easy to implement using generics as you can see from TIntegerList.

Juha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20171113/55bea53c/attachment-0001.html>

Reply by email

Michael Thompson
to Alexey: Thanks for this new list. Diff like - Result:=integer(PtrUInt(FCols[aCol])) +…

On 14 November 2017 at 01:58, Alexey via Lazarus <

Show quoted text 5 lines
wrote: shows it's useful. It supports Longint or PtrInt or PtrUInt? Or i need another list for PtrInt

You may already be aware, but check out the warnings in this page https://www.freepascal.org/docs-html/rtl/system/ptrint.html

"*The introduction of the ptrint type was a mistake. Please use ptruint <https://www.freepascal.org/docs-html/rtl/system/ptruint.html>** instead*"

Cheers

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20171114/c27c2bf9/attachment.html>

Reply by email

Kostas Michalopoulos
to Michael Thompson

That warning is misleading, makes too many assumptions about why the user needs to do something (often a common mistake when trying to "correct" others) and IMO wrong. Pointers and integers are separate things and a very common reason PtrInt and PtrUInt are used are to reserve memory in cases where you may want to store either an integer or a pointer but never both and need enough memory to hold either one (similar reason why intptr_t and uintptr_t exist in C). In that case, IntPtr is very useful when you want the integer to be signed.

For example, TComponent uses that for the Tag attribute and it is sometimes useful that you can store both unsigned integers and pointers in it.

Beyond that, it is also useful when interfacing with C code that accepts intptr_t (for the same reasons).

The warning is really like having a "warning: dont use this because it is dangerous" sticker to an industrial saw: the people buying the saw are already in a position to know what they need to use it.

Summary: the IntPtr type was far from a mistake, the warning is misleading and IMO it should be removed not only for the above reasons, but also because AFAIK not all platforms treat pointers as linear addresses (let alone signed or unsigned - for an example see i8086 pointers) and pointer arithmetic should be done with the pointer types themselves instead of converting them to integers (this is especially necessary for non-linear addresses since IntPtr(Ptr+1) might not be the same as IntPtr(Ptr)+1).

On Mon, Nov 13, 2017 at 8:16 PM, Michael Thompson via Lazarus <

Show quoted text 26 lines
wrote: On 14 November 2017 at 01:58, Alexey via Lazarus < > wrote: > shows it's useful. It supports Longint or PtrInt or PtrUInt? Or i need > another list for PtrInt > You may already be aware, but check out the warnings in this page https://www.freepascal.org/docs-html/rtl/system/ptrint.html "*The introduction of the ptrint type was a mistake. Please use ptruint <https://www.freepascal.org/docs-html/rtl/system/ptruint.html>** instead*" Cheers Mike -- _______________________________________________ Lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20171113/843791c8/attachment.html>

Reply by email