Monday, January 21, 2019

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

"Öö Tiib" <ootiib@hot.ee>: Jan 21 04:35AM -0800

On Saturday, 19 January 2019 12:37:56 UTC+2, Jorgen Grahn wrote:
> I'm curious how people use Google's AddressSanitizer with Clang and
> GCC in practice.
 
Yes, I've used it.
 
 
> CXXFLAGS+=-fsanitize=address,leak,undefined
 
> but my code didn't seem to have those flaws, apart from a leak I knew
> about already.
 
I don't care about leaks (since with RAII there are virtually none anyway).
Used _CrtSetDebugSomethingBlah of Visual Studio for that when RAII
wasn't mainstream ages ago, since it was most useful back then.
 
> what to expect from that tool. I know what errors it will flag, how
> much slower my code will run (sometimes too slow for use) and I know I
> don't have to instrument anything.
 
ASan is good with usage of object after delete/free and all sorts of
buffer overflows.
 
> - Which sanitizers do people enable, as a rule?
 
All of these but one at time.
 
> preceded by useful valgrind errors. Is the same true for ASan?
 
> - When do you use them? I suppose at least when running unit and
> component tests. Does anyone use them in production?
 
Use ASan with specially made data for stressing limits (when there
is budget for stress tests) debug with it (when there are symptoms
of those issues) and set up continuous integration to run all tests
with ASan enabled as one CI step (costs next to nothing so always).
 
> - I'm unused to tools that require instrumentation. Is it a problem
> that the standard library and other libraries aren't instrumented?
 
There are debug versions (run-time checks of most UB) with most
standard libraries. See docs for details:
https://libcxx.llvm.org/docs/DesignDocs/DebugMode.html
https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode.html
https://docs.microsoft.com/en-us/cpp/standard-library/checked-iterators?view=vs-2017
These will typically detect if code misuses operators of containers
or iterators; ASan will detect if code misuses pointer arithmetics.
Josef Moellers <josef.moellers@invalid.invalid>: Jan 21 09:24AM +0100

On 20.01.19 22:56, Vir Campestris wrote:
 
>> <https://www.cs.helsinki.fi/u/luontola/tdd-2009/kalvot/02-Code-Quality.pdf>
 
> "No lower-case L or upper-case o, ever.      int elapsedTimeInDays;"
 
> Oh look, a lower case L.
 
Yes ... as an example this is very valid!
 
I read this as "elapsedTimeInDays is bad, daysSinceCreation or
daysSinceModification or fileAgeInDays would be better".
(S)He could have made this more clear, though.
 
But you're right with the CamelCase complaint.
 
Josef
Thiago Adams <thiago.adams@gmail.com>: Jan 21 03:40AM -0800

On Sunday, January 20, 2019 at 3:26:32 AM UTC-2, Real Troll wrote:
> <https://www.cs.helsinki.fi/u/luontola/tdd-2009/kalvot/02-Code-Quality.pdf>
 
My answer for "what is clean code?" is :
 
Code where bugs find difficulties to hide themselves.
 
Generally this is associated with fast recognition about
what the code does and how.
"Öö Tiib" <ootiib@hot.ee>: Jan 21 02:34AM -0800

On Friday, 18 January 2019 16:16:07 UTC+2, Ralf Fassel wrote:
> return 0;
> }
 
> (and of course crashes at runtime...)
 
Formally the code is well formed, but reading objects before
construction is undefined behavior like reading objects
after destruction is undefined behavior. We may take
and pass references and pointers to such objects but not
to read.
 
Undefined behavior that always crashes is among best kind
of undefined behavior there is. What you complain?
 
 
> I would *at least* have expected some compiler diagnostics similar to e.g.
> int i = i;
> t.cc:7:11: warning: 'i' is used uninitialized in this function [-Wuninitialized]
 
Actually I get something like that from clang on your code:

warning: variable 's1' is uninitialized when used within its own initialization [-Wuninitialized]
 
Compilers have become very helpful these days.
 
> used before init".
 
> MSVC 2017 raises an error about s2 not being known, but if I comment
> that line out, it also compiles (and crashes)...
 
The C++ compiler vendors have put lot of effort into diagnosing
if the code is nonsensical. However in any useful language the
amount of different ways to express nonsense is endless. And
C++ is especially prone to that since language standard is
literally full of cases marked as "undefined behavior" (nonsense
that is not required to be diagnosed).
Ian Collins <ian-news@hotmail.com>: Jan 21 04:03PM +1300

On 21/01/2019 10:30, Vir Campestris wrote:
>> I've wondered
>> if 2011 C++ is the new C.
 
> You can't run any reasonable subset of C++ without an RTL.
 
Nonsense.
 
> I've run C bare metal. No RTL at all, and a few lines of assembler to
> start it up.
 
I've run C++ bare metal. No RTL at all, and a few lines of assembler to
start it up.
 
--
Ian
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jan 20 04:47PM

On 20/01/2019 16:31, Scott Lurndal wrote:
> parts of the codebase (such as soi disant smart pointers) for performance reasons.
 
> Sure, we'll eventually move forward, but that's a long process, and in the
> mean time, pre-C++11 code is required.
 
You are doing it wrong (TM).
 
/Flibble
 
--
"You won't burn in hell. But be nice anyway." – Ricky Gervais
 
"I see Atheists are fighting and killing each other again, over who
doesn't believe in any God the most. Oh, no..wait.. that never happens." –
Ricky Gervais
 
"Suppose it's all true, and you walk up to the pearly gates, and are
confronted by God," Bryne asked on his show The Meaning of Life. "What
will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery
that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a
world that is so full of injustice and pain. That's what I would say."
Daniel <danielaparker@gmail.com>: Jan 20 08:35PM -0800

Given an iterator over std::pair<T1,T2>, and wishing to adapt it to an
iterator over
 
template <class T1,class T2>
struct key_value
{
T1 key;
T2 value;
};
 
is there anything terribly wrong with
 
template <class Iter>
class iterator_adapter
{
Iter it;
public:
typedef std::input_iterator_tag iterator_category;
typedef typename std::iterator_traits<Iter>::value_type::first_type T1;
typedef typename std::iterator_traits<Iter>::value_type::second_type T2;
typedef key_value<T1,T2> value_type;
typedef value_type reference;
 
reference operator*() { return key_value(it->first,it->second); }
 
Thanks,
Daniel
Paavo Helde <myfirstname@osa.pri.ee>: Jan 21 08:25AM +0200

On 21.01.2019 6:35, Daniel wrote:
> T1 key;
> T2 value;
> };
 
Iterator is over something like std::map or std::vector, not over
std::pair, so as posed the question does not make much sense. I guess
you wanted to ask how to adapt an iterator pointing to std::pair to an
iterator pointing to key_value.
 
> typedef key_value<T1,T2> value_type;
> typedef value_type reference;
 
> reference operator*() { return key_value(it->first,it->second); }
 
As written, this is not an iterator as it is lacking an increment
operation (would be easy to add though). Also, the 'reference' type is
not a reference, misleading the user. This also means that this adaptor
can only be used as InputIterator, which severely limits its usability.
 
My question is what's the point? Basically what you have written here
just converts a std::pair to key_value. Why do you want this to happen
inside an iterator? I would iterate over the collection normally and
just convert the elements inside the loop as needed.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jan 13 12:49AM

On 13/01/2019 00:33, Rick C. Hodgin wrote:
>>> on people.
 
>> Rick, religion...
 
> Christianity isn't a religion.
 
From the Oxford English Dictionary:
 
Christianity, n.
1. The whole body of Christians, the Christian part of the world,
Christendom n. Obsolete.
2. a. The religion of Christ; the Christian faith; the system of doctrines
and precepts taught by Christ and his apostles.
 
So another lie from the deceitful Christian Rick the Dick.
 
/Flibble
 
--
"You won't burn in hell. But be nice anyway." – Ricky Gervais
 
"I see Atheists are fighting and killing each other again, over who
doesn't believe in any God the most. Oh, no..wait.. that never happens." –
Ricky Gervais
 
"Suppose it's all true, and you walk up to the pearly gates, and are
confronted by God," Bryne asked on his show The Meaning of Life. "What
will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery
that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a
world that is so full of injustice and pain. That's what I would say."
sten.unto@gmail.com (Unto Sten): Jan 12 07:58PM

> It is the enemy (Satan) at work in deceived sinners, doing
> his will in them as they are unaware due to sin's effect
> on people.
 
Rick, religion has made a moron out of you. For years you
have polluted technical, programming-related newsgroups
with spam messages that are full of outdated, delusional
ideas based on the Bible.
 
The Bible is actually one of the worst books ever written.
It consists of several contradictory smaller "books"
written by ignorant men thousands of years ago. The Bible
contains intolerance, racism, homophobia, and general beliefs
that are no more credible than fairy tales about Santa Claus.
 
The only difference is that people usually stop believing
in Santa Claus at an early age. But with Jesus-related
delusions, the false beliefs often last for a full life-time.
 
This is because many societys are nowadays pushing
Jesus-related propaganda to the members of the society.
Many people believe the Church's and priests' lies.
 
We have hundreds of different churches and sects, all
claiming to be the "really correct". It is one of
the worst features of the United States that it is
pretty full of religious wackos, but as far as I
know, the situation is getting a bit better.
 
I recently came across a study according to which the
young Americans are less religious than their parents.
Owing to the Internet, I suppose this healthy trend
will continue.
 
Rick, all I can do is hope that you will be free of
biblical delusions one day. It takes a lot of
soul-searching and honest effort from you, but
it *is* doable. But you are in *way deep*, that is clear.
 
If you cannot transition to agnosticism or atheism, please
keep "some kind of belief in some kind of God" if it helps
you to retain some kind of sanity. But definitely you should
free yourself of organized religion such as christianity
and stop spamming these newsgroups. As of now, you are not
at all mentally stable, you are a wacko.
 
Religion has molded an arrogant bastard out of you, and
that is why you think you are "helping" people here when
in reality you are only filling technical newsgroups with
unwanted, crazy, outdated, delusional christian spam.
 
Best regards,
Unto Sten
gazelle@shell.xmission.com (Kenny McCormack): Jan 13 04:34PM

In article <TrI_D.34153$Rq1.1301@fx21.fr7>,
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> wrote:
...
>Christianity is a religion.
 
Of course it is. Rick is, as usual, full of shit.
 
What else is new?
 
>[snip tl;dr]
 
Everything Rick posts is tl;dr;bs.
 
By the way, the real thing is that the word religion has taken on, among
sensible people, a negative connotation. Therefore, when marketing to
(presumably) smart people, such as you find in the Northern part of the
US and in these newsgroups, you want to downplay the word, as Rick has
done in his posts to the newsgroups. When marketing in the South, of
course, you go full on with the word, because they haven't figured out
yet what bullshit it is. They still love the word.
 
--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Noam
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jan 13 06:31AM

On Sat, 2019-01-12, seeplus wrote:
>>> come back with quotes from his zombie controller's magik book.
 
> Best you can do is get just a bit offensive with him as others do here.
> At least gives you some little satisfaction.
 
The best thing to do is not to respond, or respond privately. If you
care about the real topic of this newsgroup, that should be obvious.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
gazelle@shell.xmission.com (Kenny McCormack): Jan 13 12:27PM

In article <slrnq3lmq0.1p1h.grahn+nntp@frailea.sa.invalid>,
Jorgen Grahn <grahn+nntp@snipabacken.se> wrote:
...
>The best thing to do is not to respond, or respond privately. If you
>care about the real topic of this newsgroup, that should be obvious.
 
Right now, these newsgroups (the C/C++ groups) are about 50% about
technical (boring) stuff and about 50% about Rick's pychoses.
 
I think most people find the later half the more entertaining half.
 
--
He continues to assert that 2 plus 2 equals 4, despite being repeatedly
told otherwise.
gazelle@shell.xmission.com (Kenny McCormack): Jan 13 12:40PM

In article <q1faqn$2vl$1@news.xmission.com>,
 
>Right now, these newsgroups (the C/C++ groups) are about 50% about
>technical (boring) stuff and about 50% about Rick's pychoses.
 
>I think most people find the later half the more entertaining half.
 
I should add that one of the groups seems to be currently most concerned
with girls taken in from a blizzard (*) more than anything else.
 
(*) And the treatment and handling of hypothermia.
 
--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/LadyChatterley
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Jan 13 12:58PM -0800

On 1/13/2019 4:40 AM, Kenny McCormack wrote:
 
> I should add that one of the groups seems to be currently most concerned
> with girls taken in from a blizzard (*) more than anything else.
 
> (*) And the treatment and handling of hypothermia.
 
I had a limited conversation with very smart people wrt a seqlock and
C++. If you want on topic, read _all_ of this:
 
https://groups.google.com/d/topic/comp.lang.c++/NBZhxyzLUH8/discussion
 
Very smart people are in that thread.
Keith Thompson <kst-u@mib.org>: Jan 13 02:22PM -0800

>>> come back with quotes from his zombie controller's magik book.
 
> Best you can do is get just a bit offensive with him as others do here.
> At least gives you some little satisfaction.
 
Please don't. Replying to him just encourages him to post more,
which disrupts the newsgroup for those of us who come here to
discuss C++.
 
I don't see Rick's postings, but it's hard for my killfile to keep
up with all the people who feel the need to reply to him publicly.
 
--
Keith Thompson (The_Other_Keith) kst@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
gazelle@shell.xmission.com (Kenny McCormack): Jan 13 10:51PM

In article <ln8szodwq8.fsf@kst-u.example.com>,
Keith Thompson <kst-u@mib.org> wrote:
...
>discuss C++.
 
>I don't see Rick's postings, but it's hard for my killfile to keep
>up with all the people who feel the need to reply to him publicly.
 
You should probably look into setting up your newsreader to have a
whitelist (i.e., a list of the few people who post here whose stuff you
actually will deign to read) rather than trying to maintain a blacklist.
 
--
Faith doesn't give you the answers; it just stops you from asking the questions.
Melzzzzz <Melzzzzz@zzzzz.com>: Jan 13 02:53AM


> https://duckduckgo.com/?q=next+big+thing+andrei&t=ffab&ia=videos&iax=videos&iai=tcyb1lpEHm0
 
> Andrei says, "We want to generate code that matters".
> The story about the guy on the plane was interesting.
 
Can you make short description if you wathed video?
 
--
press any key to continue or any other to quit...
red floyd <no.spam@its.invalid>: Jan 12 08:19PM -0800

On 1/12/19 8:07 PM, Melzzzzz wrote:
 
>> I think on-line code generators will have a portability
>> edge over D compilers.
 
> Why?
 
Because he has one of the former.
Melzzzzz <Melzzzzz@zzzzz.com>: Jan 13 09:20PM


>> Well, it uses library. This is not just 35 lines.
 
> That's true for most C++ programs. If the platform
> has 2017 C++ support, this program will likely build.
fatal error: cmw/Buffer.hh: No such file or directory
#include<cmw/Buffer.hh>
 
> a software development tool. People use routers to
> support their desktops and phones, right? And they
> use their desktops and phones for software development.
 
Phones are phones. Developing for phones is less likely to use some C++.
Router more likely...
 
--
press any key to continue or any other to quit...
Melzzzzz <Melzzzzz@zzzzz.com>: Jan 13 10:38PM


> Thanks for the report. What operating system are
> you using? And what is the build line that is failing?
> Something like: g++ ...
 
Linux, g++ 8.2.1, that build line fails. 35 lines of code, but no cmw/Buffer.hh
on my system...
 
>> Router more likely...
 
> The point is you would be using a desktop to develop
> for routers.
 
Sure.
 
--
press any key to continue or any other to quit...
sten.unto@gmail.com (Unto Sten): Jan 13 06:08AM

> if the lambda is passed over to another thread or stored for later use,
> for example. Note that std::find_if does not know or care about x, it
> just (potentially) copies and invokes the lambda.
 
Okay, thanks for this. I will save the whole discussion thread and
get back to it later.
 
> An extract from real production code: [...]
 
I am hopelessly bad with 3D math, so I do not understand the code,
but I am sure it is helpful to those who get the 3D stuff.
 
Best regards,
Unto Sten
Paavo Helde <myfirstname@osa.pri.ee>: Jan 12 10:50PM +0200

On 12.01.2019 17:26, Unto Sten wrote:
 
> Okay, I have to study more about lambdas. Could you refer to some
> C++ example code that demonstrates the functor property of lambda
> functions?
 
The simplest example: find an element in a vector not equal to x.
 
int x = 42;
std::vector<int> v= ...;
auto p = std::find_if(v.begin(), v.end(), [x](int y){return x!=y;});
 
Note passing the data to lambda via [x]. If it were [&x] then it would
just store a reference to the original x. This would make a difference
if the lambda is passed over to another thread or stored for later use,
for example. Note that std::find_if does not know or care about x, it
just (potentially) copies and invokes the lambda.
 
An extract from real production code:
 
// Parallelize over 2D planes of a 3D array
CubeParallelizer2 parallelizer(ctx.GetEngine(), dims);
parallelizer.PlaneLoop(ctx,
[this, dims, &sourcePlanePointers, &maskPlanePointers, &pHess1,
&pHess2, &pHess3, &pNegTrace, sourceType, resultType]
(dimsize_t z)
{
Run3DPlane(
z > 0 ? sourcePlanePointers[z - 1] : nullptr,
sourcePlanePointers[z],
z < dims[2] - 1 ? sourcePlanePointers[z + 1] : nullptr,
dims[0],
dims[1],
maskPlanePointers[z],
pHess1[z],
pHess2[z],
pHess3[z],
pNegTrace[z],
sourceType,
resultType
);
});
 
Here a lambda is passed over to parallel worker threads, with some bound
data passed by reference and some by value. Note that the parallelizing
infrastructure (parallelizer.PlaneLoop()) does not know or care about
the bound data, it just copied and invokes the lambda. Note also how the
bound data and the explicit parameter z are combined for selecting the
data to use in the other thread.
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Jan 13 07:49PM

On Sat, 12 Jan 2019 17:34:59 -0000 (UTC)
> examples using lambda functions, but have been unable
> to see what's the actual benefit of using closures in
> the first place.
 
One common use of closures is for partial application (which you can
google for in your own time), converting a function taking some
arguments into a function taking less or no arguments. (A value bound
or captured from the environment by a closure is somewhat confusingly
called a "free variable" in the lambda calculus.)
 
In C++ std::bind can also be used to construct closures, and you can
read up on that too.
 
But don't underestimate the usefulness of lambda expressions for other
purposes, particularly as temporary unnamed function objects. They can
be very useful for passing "on the fly" to functions taking callable
objects - the algorithms in the standard library have many such
functions. It makes code much more readable when done properly.
David Brown <david.brown@hesbynett.no>: Jan 12 06:33PM +0100

On 11/01/19 17:20, Kenny McCormack wrote:
> different nonsense, via the same methods. Among other things, your
> Trumpian, supreme, unshakable confidence in your own infallibility.
 
> Such a cute couple you'd make...
 
Did I understand you correctly? You think "C is a high level language,
not an assembly language" is a wacko idea? Are you sure you are in the
right newsgroup? Are you sure you are on the right planet? I can
understand that some people would /prefer/ C to be a sort of "high level
assembler" - that's a matter of opinion. I can understand that some
people try to use it that way, and that some people think that was what
it used to be - those are mistakes made from ignorance and misunderstanding.
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: