Tuesday, May 18, 2021

Digest for comp.lang.c++@googlegroups.com - 25 updates in 2 topics

Branimir Maksimovic <branimir.maksimovic@gmail.com>: May 17 11:24PM

> [snip buggy code that seems to work in MSVC]
>> _______________________________
 
> Now, this version should go ahead and work? It seems to.
 
Correcti, first version segfaults because temporary and I have warning,
second version does not has warning and works.
 
 
--
current job title: senior software engineer
skills: x86 aasembler,c++,c,rust,go,nim,haskell...
 
press any key to continue or any other to quit...
Mike Terry <news.dead.person.stones@darjeeling.plus.com>: May 18 05:01PM +0100

On 18/05/2021 00:05, Chris M. Thomasson wrote:
 
>     return 0;
> }
> _______________________________
 
Posting around 150 lines of code, then asking "why doesn't this
segfault?" with no further explanation isn't good. It would have been
helpful at least have said which bit of code you thought should produce
a segfault...
 
OK, so I guess your issue is with the two search_id functions, which
return a reference to a local result, e.g.:
 
> {
> return m_set.find(id);
> }
 
When these are used you expect a segfault, but when I run the code (MSVS
17) there is no seg-fault because the original iterator storage on the
stack hasn't been overwritten at that point. (There is a compile
warning "returning address of local variable or temporary".)
 
The obvious correct approach would be to just return the iterator by
value. (And I'd wonder why would you want to make it const, but I
suppose this is some kind of experiment rather than production code.)
 
 
Mike.
Bonita Montero <Bonita.Montero@gmail.com>: May 18 06:12PM +0200

> >      {
> >          return m_set.find(id);
> >      }
 
Totally brain-damaged.
Mike Terry <news.dead.person.stones@darjeeling.plus.com>: May 18 05:19PM +0100

On 18/05/2021 00:11, Chris M. Thomasson wrote:
 
>     return 0;
> }
> _________________________________
 
..so now you've corrected the search_id() methods to return the iterator
by value (good). But now you're receiving them as references to a const
iterator, i.e. you're taking an rvalue result and extending its lifetime
by taking a const reference to it. That is allowed, but is bizarre in
this situation. I'm not sure why it would ever be good to do this, but
I've not thought very much about it. (If you were a beginner, I'd say
you should be just storing the value...)
 
Mike.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: May 18 10:29PM +0200

On 18.05.2021 01:05, Chris M. Thomasson wrote:
> I don't think this should work at all! It should segfault.
 
>     set_t::iterator const& search_id(unsigned long id) const
 
Well UB is UB. That includes that things may appear to work.
 
- ALf
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: May 18 02:50PM -0700

On 5/18/2021 9:12 AM, Bonita Montero wrote:
>>  >          return m_set.find(id);
>>  >      }
 
> Totally brain-damaged.
 
:^)
 
I was just wondering why MSVC allows this to run in the first place.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: May 18 02:59PM -0700

On 5/18/2021 9:01 AM, Mike Terry wrote:
> On 18/05/2021 00:05, Chris M. Thomasson wrote:
>> I don't think this should work at all! It should segfault.
>> _______________________________
[...]
> segfault?" with no further explanation isn't good.  It would have been
> helpful at least have said which bit of code you thought should produce
> a segfault...
 
Yeah, sorry about that.
 
 
 
> The obvious correct approach would be to just return the iterator by
> value.  (And I'd wonder why would you want to make it const, but I
> suppose this is some kind of experiment rather than production code.)
 
It is a crude quick experiment. I never used is_transparent before. Then
I noticed that MSVC actually runs the bugged code. I got the warnings as
well, but still wondered about why it ran to completion.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: May 18 03:05PM -0700

On 5/18/2021 9:19 AM, Mike Terry wrote:
>>> _______________________________
 
>> Now, this version should go ahead and work? It seems to.
>> _________________________________
[...]
>>      {
>>          return m_set.find(name);
>>      }
[...]
> this situation.  I'm not sure why it would ever be good to do this, but
> I've not thought very much about it.  (If you were a beginner, I'd say
> you should be just storing the value...)
 
Well, I was thinking that searching for something in the database using
a function qualified as const, should return a const iterator. So I just
added in the const keyword in vain. Its been a while since I used the
STL. Take mercy on my soul!
 
;^o
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: May 18 03:09PM -0700

On 5/18/2021 1:29 PM, Alf P. Steinbach wrote:
>> I don't think this should work at all! It should segfault.
 
>>      set_t::iterator const& search_id(unsigned long id) const
 
> Well UB is UB. That includes that things may appear to work.
 
Indeed. Mike Terry mentioned something about a stack issue.
"Öö Tiib" <ootiib@hot.ee>: May 17 07:53PM -0700

On Monday, 17 May 2021 at 11:45:21 UTC+3, Bonita Montero wrote:
> > based to that is decided what members the set has.
> But why is this actually necessary ? operator [] could
> forward any parameter for comparison to the ()-operator.
 
I do not understand what you ask ... std::set does not have
operator [] AFAIK.
Bonita Montero <Bonita.Montero@gmail.com>: May 18 05:39AM +0200

> I do not understand what you ask ... std::set does not have
> operator [] AFAIK.
 
I'm asking for associative containers.
"Öö Tiib" <ootiib@hot.ee>: May 17 10:33PM -0700

On Tuesday, 18 May 2021 at 06:39:41 UTC+3, Bonita Montero wrote:
> > I do not understand what you ask ... std::set does not have
> > operator [] AFAIK.
> I'm asking for associative containers.
 
Give some hint about topic change as you started by citing article
"How to search a C++ set with another type than its key" and
then replied to my explanation that did talk nothing about maps :
> Compare is injected to std::set compile time, if it has
> is_transparent member is also evaluated compile time and
> based to that is decided what members the set has.
 
The map::operator[] does not have template
versions regardless of is_transparent for obvious reasons
and unordered_map does not have any support to
transparency yet.
Juha Nieminen <nospam@thanks.invalid>: May 18 06:47AM

> Juha, I've just added "MrSpook" to my killfile. I'm seriously
> considering adding you as well. Please knock it off.
 
I have been using Usenet since about 1995, and to this day I seriously
cannot understand the motivation for killfiles. I'm being completely
serious here. What exactly do you gain from them?
 
Even when you add people to your killfile you are going to see their
posts anyway, because people respond to them and quote them. It will
break threads and make them disjointed. You are most probably going to
ignore such threads anyway, so what's the point in the killfile?
 
This especially so nowadays, when Usenet is almost dead. Perhaps back
in the day when a Usenet group like this one got literally thousands
and thousands of posts every day, maybe the killfile would reduce the
amount of posts somewhat, by hiding the posts of certain individuals.
Nowadays, however, Usenet is almost completely dead, and even the still
most popular groups get maybe half a dozen posts per day... on busy days.
 
What would you gain from adding eg. me to your killfile? I'm asking
seriously. You want to hide all of my posts from your view because I threw
insults at someone in one single random thread? Why? What exactly do you
gain from this?
MrSpook_7kof@5x9.edu: May 18 07:27AM

On Mon, 17 May 2021 16:37:18 +0000 (UTC)
>> '///,`,--.,' `-.__.--' `. )
>> '///,' `-`
 
>Why don't you just go fuck yourself, asshole?
 
LOL :) Looks like the swearbot is stuck on auto repeat!
MrSpook_w2uom3_k07@47j.ac.uk: May 18 07:30AM

On Tue, 18 May 2021 06:47:37 +0000 (UTC)
>seriously. You want to hide all of my posts from your view because I threw
>insults at someone in one single random thread? Why? What exactly do you
>gain from this?
 
Wow, talk about a total lack of self awareness. You decided to pick a fight
just because I criticised an aspect of C++ and now you're whining because
someone got sick of your potty mouth? Pathetic.
Juha Nieminen <nospam@thanks.invalid>: May 18 10:31AM

> Wow, talk about a total lack of self awareness. You decided to pick a fight
> just because I criticised an aspect of C++ and now you're whining because
> someone got sick of your potty mouth? Pathetic.
 
Just fuck off, asshole. As an asshole, you can't spout anything but shit.
Ben Bacarisse <ben.usenet@bsb.me.uk>: May 18 01:08PM +0100


> I have been using Usenet since about 1995, and to this day I seriously
> cannot understand the motivation for killfiles. I'm being completely
> serious here. What exactly do you gain from them?
 
I use GNUS (I think Keith does too) and while it has a kill file, it
also has a flexible scoring system. The score can be based on all sorts
of criteria like who the poster is, the number of cross-postings, the
thread it's in, who it is in reply to and so on. I can then have
low-scoring posts marked as read, greyed-out but still shown in the
thread tree. I can see at a glance, when opening a group, if it's all
troll posts and replies to such.
 
> Even when you add people to your killfile you are going to see their
> posts anyway, because people respond to them and quote them.
 
GNUS can even score based on quoted material, but that's a bit more
costly. You can always score down people who quote troll posts, and if
you pick a score that requires another factor to make the post "vanish"
you will still see the quoter's posts in other contexts.
 
> Nowadays, however, Usenet is almost completely dead, and even the still
> most popular groups get maybe half a dozen posts per day... on busy
> days.
 
This is true. GNUS was super efficient in those days. It still let's
me read news fast, but the major advantage is dwindling.
 
--
Ben.
Manfred <noname@add.invalid>: May 18 05:10PM +0200

On 5/18/2021 8:47 AM, Juha Nieminen wrote:
 
> I have been using Usenet since about 1995, and to this day I seriously
> cannot understand the motivation for killfiles. I'm being completely
> serious here. What exactly do you gain from them?
 
Killfiles are vital to Usenet. The main reason it is almost dead today
is because of compulsive trolls flooding this space with their nonsense.
The strongest feature of Usenet is freedom, but from the perspective of
such trolls it is its deepest weakness.
Killfiles, especially the good ones, are a sensible defense against that
- they are what keeps what's left of Usenet alive, literally.
 
> posts anyway, because people respond to them and quote them. It will
> break threads and make them disjointed. You are most probably going to
> ignore such threads anyway, so what's the point in the killfile?
 
Good killfiles are able to follow threads and kill replies too - the
main defect I see today is with google groups (again) because it manages
a.o. to disrupt thread continuity, but luckily a lot of threads get
handled properly.
 
> amount of posts somewhat, by hiding the posts of certain individuals.
> Nowadays, however, Usenet is almost completely dead, and even the still
> most popular groups get maybe half a dozen posts per day... on busy days.
 
Even if it is (unfortunately) almost dead, why push the trend?
 
> seriously. You want to hide all of my posts from your view because I threw
> insults at someone in one single random thread? Why? What exactly do you
> gain from this?
 
Not you specifically, since this is probably one of the first
occurrences, but in general it is about reducing noise, obviously
disturbing noise.
MrSpook_axe6hb@rq6ypc_knzvwr9.ac.uk: May 18 03:11PM

On Tue, 18 May 2021 10:31:40 +0000 (UTC)
>> just because I criticised an aspect of C++ and now you're whining because
>> someone got sick of your potty mouth? Pathetic.
 
>Just fuck off, asshole. As an asshole, you can't spout anything but shit.
 
Are you having some kind of mental breakdown?
Manfred <noname@add.invalid>: May 18 05:20PM +0200


> I'm talking about the syntax , not the concept. Wtf is "= 0"? Its an ugly
> syntactic hack. They already created the new keyword "virtual" so why didn't
> they create another one called "pure"?
 
This was indeed somewhat weird of a choice. I used to have a sense that
it was meant to be somehow expanded to other uses where the '0' would be
replaced with something else. But this never turned out to be the case,
at least in standard C++.
 
I seem to remember that the Borland C++ compiler would allow some
extension like
 
virtual LRESULT OnPaint(...) = WM_PAINT;
 
Which sounds appealing, but in fact it fades away in very old memories -
maybe someone else may recall anything more clear about that, if this
was indeed a thing at all.
MrSpook_h2j5v@jq7cn18h8lm.com: May 18 03:35PM

On Tue, 18 May 2021 17:20:13 +0200
 
>Which sounds appealing, but in fact it fades away in very old memories -
>maybe someone else may recall anything more clear about that, if this
>was indeed a thing at all.
 
I remember that anything other than zero would crash a number of older versions
of the solaris compiler back in 00s.
Bonita Montero <Bonita.Montero@gmail.com>: May 18 05:56PM +0200

> This was indeed somewhat weird of a choice. ...
 
For me that's syntactically expressive enough to be noticed.
 
> I seem to remember that the Borland C++ compiler would allow some
> extension like
> virtual LRESULT OnPaint(...) = WM_PAINT;
 
Who programs Win32 directly today ?
Even with MFC you've got message-maps.
James Kuyper <jameskuyper@alumni.caltech.edu>: May 18 11:56AM -0400

On 5/18/21 2:47 AM, Juha Nieminen wrote:
> serious here. What exactly do you gain from them?
 
> Even when you add people to your killfile you are going to see their
> posts anyway, because people respond to them and quote them. ...
 
True, but you'll see fewer of them. In many cases, I'll miss most or
even all of an entire conversation because I have everyone participating
in it in my killfile.
 
> ... It will
> break threads and make them disjointed. ...
 
If I see a broken thread, the simple fact that it's broken suggests that
one of the participants is in my killfile, making its somewhat easier to
quickly identify the thread as one to be ignored. In particular, I
occasionally have trouble remembering some people who have been in my
killfile for a long time, but I'm still protected from them, because my
newsreader has more reliable memory than I do.
 
 
> This especially so nowadays, when Usenet is almost dead. Perhaps back
> in the day when a Usenet group like this one got literally thousands
> and thousands of posts every day,
 
Back in August 2011, when Google was still providing statistics about
newsgroup participation, I responded to a message claiming that
comp.lang.c was dead:
 
[I wrote:]
> single month. Don't pay too much attention to the July and August
> numbers; something has been going wrong with Google Groups for the past
> several weeks.
 
I can't check to verify this anymore, but I seem to recall that
comp.lang.c++ generally had somewhat lower message counts than
comp.lang.c, so I don't think it has ever been as high as "thousands per
day". Those kinds of numbers only happened for newsgroups catering to
large and active fan groups. For example, I remember seeing huge counts
in 2001 for alt.tv.buffy-v-slayer.
 
[Juha wrote:]
> seriously. You want to hide all of my posts from your view because I threw
> insults at someone in one single random thread? Why? What exactly do you
> gain from this?
 
I can't speak for Keith, but I doubt that he's responding to just this
recent series of messages. I have noticed a tendency for you to get into
uninteresting insult matches with people who, admittedly, deserve the
insults - but I'm not interested in seeing those insults. If Keith
decides to put you in his killfile, he'll spend less time reading those
insults, and I wouldn't be surprised if that's what he hopes to gain
from doing that.
Bonita Montero <Bonita.Montero@gmail.com>: May 18 05:57PM +0200

> I remember that anything other than zero would crash a number
> of older versions of the solaris compiler back in 00s.
 
The numer isn't parsed as a number, but just a "= 0"-token,
so you're lying.
Manfred <noname@add.invalid>: May 18 08:03PM +0200

On 5/18/2021 5:56 PM, Bonita Montero wrote:
>> virtual LRESULT OnPaint(...) = WM_PAINT;
 
> Who programs Win32 directly today ?
> Even with MFC you've got message-maps.
 
The point is about the syntax, not Windows programming. That is, again,
if my memory doesn't fail me. It's getting close to being 30 years ago.
 
Still, the capability of indexing into a vtable...
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: