Tuesday, November 5, 2019

Digest for comp.lang.c++@googlegroups.com - 1 update in 1 topic

David Brown <david.brown@hesbynett.no>: Nov 05 11:14PM +0100

On 05/11/2019 19:31, Manfred wrote:
> From this perspective I like compiler flags more than adding new source
> code constructs. Maybe because I think that signed wrapping, unlike
> unsigned, is of no practical use.
 
Personally, I think signed wrapping is only useful very occasionally -
and unsigned wrapping only slightly more often. But when you need
wrapping, it is a lot more efficient to have it than to have to mess
around with checks for overflows.
 
I don't like compiler flags as a solution here, because it is
disconnected from the code. (Though flags are excellent for when you
have to work with code written by someone who doesn't understand the
language and has only tested with inferior compilers.) If I have code
that makes use of additional semantics, like wrapping integers or
invalid pointer casts, I put the flags in the code as pragmas (or gcc
function attributes). That way the code will work regardless of the
flags used to compile the code. It also gives a fine place to put
comments explaining the issue.
 
> That's my first - unsigned wrapping /can/ be useful in some contexts. I
> can't say if it is about the majority of cases, but it is enough to keep
> it in place.
 
I think it can be agreed that sometimes the wrapping is useful, and
sometimes it is a programming error. But people disagree about the
split, both for signed and unsigned types.
 
> Disagree. It is not always important, but it is important enough to be
> one of the main reasons to choose C++, so it should be of primary
> importance for the language.
 
There are many good reasons for choosing C++ other than efficiency. It
is a well-established fact that in almost all code, only small sections
are performance critical. That does not mean we want intentionally
inefficient code in the rest of it, of course. And if the code gets
full of run-time checks then it /would/ end up as inefficient.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: