[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: preferring ptrdiff_t to size_t for object counts
From: |
Bruno Haible |
Subject: |
Re: preferring ptrdiff_t to size_t for object counts |
Date: |
Mon, 05 Jun 2017 12:07:15 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-78-generic; KDE/5.18.0; x86_64; ; ) |
Hi Paul,
I'd like to understand how much better this "ptrdiff_t world" is.
> This has the advantage that signed integer overflow can be detected
> automatically on some platforms
You mean "-fsanitize=undefined", right?
Does this also catch the following situations?
a) Pointer subtraction. ISO C11 ยง J.2 says:
"The behavior is undefined in the following circumstances: ...
The result of subtracting two pointers is not representable in an object
of type ptrdiff_t (6.5.6)."
b) When assigning a 'size_t' value > PTRDIFF_MAX to a 'ptrdiff_t' variable,
is that undefined behaviour? Is that caught by "-fsanitize=undefined"?
Bruno