[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: intptr_t vs. uintptr_t
From: |
Bruno Haible |
Subject: |
Re: intptr_t vs. uintptr_t |
Date: |
Sat, 14 Dec 2019 03:35:09 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; ) |
Paul Eggert wrote:
> https://www.gnu.org/software/emacs/manual/html_node/elisp/C-Integer-Types.html
Quoting it:
"Prefer intptr_t for internal representations of pointers"
I disagree with this advice. uintptr_t ought to be used for representing the
address of a pointer.
Why? Because when signed comparisons or pointer differences come into play,
- uintptr_t creates a boundary line at 0x00000000,
- intptr_t creates a boundary line at 0x80000000.
Now look at the virtual memory map of a process (e.g. by compiling vma-iter.c
with -DTEST).
On all OSes, there is a natural boundary line at 0x00000000 - simply because
there is the null-pointer catching area there.
On many OSes, memory allocations can lie around 0x80000000.
So, it is possible to have ptr1 = 0x7fffc000 and ptr2 = 0x80003000 point into
the same object (allocated through mmap or malloc). Then
- you DO want ptr1 < ptr2 to evaluate to true, not false,
- you DO want ptr2 - ptr1 to evaluate to 0x7000, not to a signed integer
overflow.
Bruno
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, Paul Eggert, 2019/12/11
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/12
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/12
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/12
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, Paul Eggert, 2019/12/12
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/13
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/13
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, Jim Meyering, 2019/12/13
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, Paul Eggert, 2019/12/13
- Re: intptr_t vs. uintptr_t,
Bruno Haible <=
- Re: intptr_t vs. uintptr_t, Paul Eggert, 2019/12/13
- Re: intptr_t vs. uintptr_t, Bruno Haible, 2019/12/14
- Re: intptr_t vs. uintptr_t, Paul Eggert, 2019/12/14
- Re: intptr_t vs. uintptr_t, Bruno Haible, 2019/12/14
- Re: intptr_t vs. uintptr_t, Paul Eggert, 2019/12/16
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/15
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, Paul Eggert, 2019/12/16
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/16
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, Paul Eggert, 2019/12/19
- Re: bug#34951: [PATCH] grep: a kwset matcher not work in a grep matcher, arnold, 2019/12/20