Tuesday, October 2, 2018

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

Ian Collins <ian-news@hotmail.com>: Oct 02 11:25PM +1300

On 02/10/18 18:30, Juha Nieminen wrote:
> other young earth creationists, and avoiding answering any questions.
> You have no interest in actually having a conversation, you only spout
> doctrine like a mindless robot.
 
https://www.psychologytoday.com/us/blog/ambigamy/201403/why-won-t-they-listen-reason
 
--
Ian
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 02 04:55AM -0700

On Tuesday, October 2, 2018 at 12:49:41 AM UTC-4, Reinhardt Behm wrote:
> > It was man's sin that destroyed that perfection.
 
> He created everything. So he also created sin. Bad design, incompetent
> designer. Broken by design.
 
That is the enemy's voice speaking through your mind, Reinhardt.
 
God created everything perfect. God created man and gave him
truly a free will. God didn't create zombie robots parroting
His commands, obeying Him then without question because they
were programmed to do so.
 
Instead, He created a family. Those who are like Him, made in
His own image and likeness, such that we can commune with Him.
 
He made us to be unique, independent, free thinkers. And He
guided Adam and Eve, and He guides us in the way(s) we should
go. He warns about the cost of sin (loss of eternal life, of
their eternal soul).
 
And yet ... even in our rebellion against Him, still He gave
us a second chance by sending us Jesus to take our sin away...
to make a way back to be with Him.
 
-----
The enemy is already lost, Reinhardt. He knows his future is
the eternal lake of fire. So he spreads his nets, and casts
out his lies in the hopes that you, and others, will believe
those lies, and it will keep you from coming to God.
 
The response David Brown gives, it's a perfect example of how
the enemy provides reasons which seem to make sense to our
flesh as to the cause of things, but they deny God, and they
deny His authority, and they deny the need for Jesus Christ
to forgive our sin.
 
It is there the enemy is found (in lies). And it is there
Jesus is found (in truth, for He is truth, the author of it,
and the embodiment of all truth). Jesus said, "When you hear
the truth, you hear my voice."
 
It's before you, Reinhardt. It's not my job to make you or
anyone else believe. It /IS/ my job to teach you the truth,
and to reach out to you in a multitude of ways to bypass the
enemy's influence on you, seeking to provide the methodology
that will reach and touch you.
 
Try and look past "Rick" ... and try and see "Jesus" alone.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 02 05:02AM -0700

> > Fwiw, I always thought the the book of Job mentioned the "Behemoths"...
> > Was it referencing dinosaurs? Iirc, some said they had a tail the size
> > of the trunk of the Cedars of Lebanon.
 
I didn't answer you, Chris, because you can look it up yourself.
I did a Google search for "bible gateway kjv job cedar":
 
https://www.biblegateway.com/passage/?search=Job+40%3A15-24&version=KJV
 
If you read in Young's Literal Translation, you see the wording
which most closely resembles the original text:
 
https://www.biblegateway.com/passage/?search=Job+40%3A15-24&version=YLT
 
17 He doth bend his tail as a cedar, The sinews of his
thighs are wrapped together,
 
How is it cedars bend? Is it at the hips and reach down and
touch the floor? Or do they not bend, and therefore the motion
of bending is describing the size of tail?
 
Behemoth is described as the chief of the ways of God:
 
18 His bones are as strong pieces of brass; his bones
are like bars of iron.
19 He is the chief of the ways of God: he that made him
can make his sword to approach unto him.
 
And the entire passage is describing his form, mobility,
stature, and demeanor. It is stating that Job should look
to his creature, which did live with him at that time, which
God Himself is teaching Job did exist with man in Job 40.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 02 05:09AM -0700

On Tuesday, October 2, 2018 at 1:30:38 AM UTC-4, Juha Nieminen wrote:
> I notice that you never answer any questions...
 
I've tried to teach this before: But one of the enemy's traps
is to try to pigeonhole a response from someone on the things
of God.
 
The equivalent statement of, "You must come to me this way, on
my terms, describing the exact answers to my questions, no more,
and no less."
 
The enemy uses that approach because that's his domain. He's
already prepared your thinking against God in those areas, so
any information cast into that field will be easily deflected.
 
What God provides to people is truth, and truth is a native
thing. It exists fundamentally and is as it is, and is not
like anything else. Lies and falsehood can be like other things,
but truth cannot. It is always fully distilled, undiluted, pure,
and full of purpose and vision.
 
-----
What I teach you is about sin, Juha. It's about your sin before
God. It's about the punishment of sin upon your own soul, and
that means being cast forever into the eternal lake of fire. It
is about Jesus coming to this Earth to take your sin away and
give you the only way out of that condition.
 
I'm teaching you to look at the things of God which are revealed
to us over 1000s of years, and consider that God is considering
eternity in your future, and not just your N years here on this
Earth.
 
The Old Testament was written over 1500 years. The New Testament
was written within about 60 years of Jesus' crucifixion, but both
of them were written for us, the people yet to come, which would
be here at the end-times.
 
-----
The Bible has not been given mankind for nothing. And I urge you
to read it, and to approach it with a truth-seeking heart.
 
I urge you to turn off the music, turn off the TV, turn off the
distractions, and there in the silence, look at yourself in the
eyes in the mirror and tell me if I'm lying to you? Tell me if
I am advising you in any wrong way. Tell me if I have some kind
of deceptive ulterior motive in advising you to go to Jesus and
ask forgiveness for your sin, if I'm going to somehow gain in you
doing that, apart from gaining a brother in Christ?
 
You'll find that you can deceive me, you can even deceive your-
self at times, but you cannot deceive God. When you look into
your eyes in the mirror when there are no other distractions,
you will know in your soul that what I am teaching you is true.
 
The same goes for all of you.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 02 05:13AM -0700

On Tuesday, October 2, 2018 at 6:26:24 AM UTC-4, Ian Collins wrote:
> https://www.psychologytoday.com/us/blog/ambigamy/201403/why-won-t-they-listen-reason
 
Ian, the enemy creates false reasons, alternate ideas, things that
sound tangible to our minds, ways of discounting God, of stating
that the things here in the natural are all there is, and there are
valid, scientific, materially-focused reasons for the reasons why
the way things are.
 
But it's a lie.
 
There is an active enemy here at work against all people world-
wide. That enemy is introducing things contrary to God's teaching,
contrary to the truth, contrary to God's guidance, and that enemy
is doing it to deceive people into believing the lie and remaining
in their sin.
 
What Jesus did was make a way out of that, and all who will seek
the truth, who desire to not be deceived, who desire to seek and
seriously pursue the truth to know the truth for real, all of
these are known to God, and they will be drawn out from the enemy
of this world, have his blinders on their mind removed as God
pours out His spirit of truth upon them, so that they are changed
from within, able to overcome that enemy, drawn from within to
come to Jesus and ask forgiveness so they can be saved.
 
The rest will literally perish in their sin on judgment Day.
 
I teach you these things because today you can still be saved.
Tomorrow may be too late. Tomorrow may never come. Today is
the day of salvation ... and yes, there is a real urgency, for
none of know which heartbeat will be our last.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 02 05:17AM -0700

On Tuesday, October 2, 2018 at 3:28:16 AM UTC-4, David Brown wrote:
> A classic case is the human eye - they can't see
> the point of "half an eye", therefore they don't think it evolved.
 
You are made blind by the enemy, David, who appeals to your love
of sin. He has the wool pulled over your eyes and is whispering
his lies into your ears, keeping you in an artificial construction
of his plans for your future, which is to see you leave this world
without being forgiven of your sin, to then have you placed into a
position where God is /FORCED/ to judge you, to then have your own
eternal soul cast headlong into the lake of fire forever.
 
That enemy has designs on your future, designs on your present,
designs on your soul. He is already a lost creation, condemned by
what Jesus did at the cross. He is a defeated foe who seeks now
to take down as many as he can with him.
 
Don't be one of them, David. Put in the effort to seek the truth
and to know it and to be set free by coming to it.
 
I cannot help but pray for you and many others here. The love God
gave me, that lives in my heart, demands it, because I care about
you. I do not want to see you perish in eternity. I want to see
you alive in eternity, thriving in the paradise of God.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 02 05:32AM -0700

On Tuesday, October 2, 2018 at 8:02:21 AM UTC-4, Rick C. Hodgin wrote:
> stature, and demeanor. It is stating that Job should look
> to his creature, which did live with him at that time, which
> God Himself is teaching Job did exist with man in Job 40.
 
BTW, here you can see how the enemy works. God states something.
This opens up the opportunity for the enemy to state something
else. God states "Job lived with dinosaurs," and that "man in
general lived with dinosaurs" (Job 41:5).
 
Because God says X, the enemy has the opportunity to introduce
sin which says Y, or A, or B, or Z, or Q.
 
There is one correct answer to the question: "How old are you?"
But there are many lies.
 
Satan uses this ability to have many lies to create scenarios
which will appeal to your flesh. God says (paraphrased) "Examine
the dinosaurs, the mighty creatures that are chief of my works."
So the enemy says, "Dinosaurs didn't live with man. They died
millions of years ago. Perhaps some survived, but the fossils
you find, those are all millions of years old."
 
It's the lie ... sent forth to deceive. And it will entangle
all who are no looking for the truth.
 
Soft tissue and DNA have been found in tact in dinosaur
bones that mainstream science would report are millions
of years old (DNA can't last more than a few thousand
years if kept in ideal conditions, let alone buried in
the Earth):
 
Evidence that Dinosaurs Died Thousands (not Millions) of
Years Ago:
https://www.youtube.com/watch?v=zF7qOciAu04
 
--
Rick C. Hodgin
boltar@cylonhq.com: Oct 02 12:32PM

On Tue, 2 Oct 2018 05:09:34 -0700 (PDT)
 
>I've tried to teach this before: But one of the enemy's traps
>is to try to pigeonhole a response from someone on the things
>of God.
 
So the Bible has the answers but when people ask questions and expect some
you claim its the enemy? What a nice simplistic way of deflection - if your
non specific vague replies don't work then claim the questioner is at fault.
 
https://yourlogicalfallacyis.com/tu-quoqueo
 
Try harder Rick.
David Brown <david.brown@hesbynett.no>: Oct 02 02:38PM +0200

On 02/10/18 14:17, Rick C. Hodgin wrote:
>> A classic case is the human eye - they can't see
>> the point of "half an eye", therefore they don't think it evolved.
 
> You are made blind by the enemy,
 
No, Rick, /you/ are blind - you have locked yourself into this vicious
circle of idiocy. For some bizarre reason (given your descriptions, it
was perhaps a nervous breakdown) you have decided that an absurdly
literal reading of some few parts of Genesis is "true". In order to
keep that, you need to have odd interpretations of all sorts of other
parts of the Bible, and /completely/ scrambled views on reality and
science. You have thrown all rational thought, logic, and critical
thinking out of the window. This is very far from Christianity - a key
aspect of a true relationship with god (whatever god you want) is to
make use of the "gifts" you are given. You, however, are utterly
rejecting the "gift" of reason - if there is a god out there somewhere,
that must be a terrible insult to him/her/it.
 
You have got yourself into a cult. It's the same mental process as
conspiracy theorists who take any proof that they are wrong as proof
that the conspiracy is even bigger - it is paranoid delusion.
 
Of course, it is unlikely that it will help to be told this. It is very
difficult to undo the kind of brainwashing you have let yourself in for
- and it rarely happens voluntarily.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 02 08:48AM -0400

On 10/2/2018 8:38 AM, David Brown wrote:
> [snip]
 
I used to believe as you do, David. The words you write here
could've been written by me to another /BEFORE/ I came to Christ
in 2004.
 
When the change happened ... I could not believe it. I could
not believe how I changed, and how all things were different.
 
It takes an act of God to restore our dead spirit so that we
can then understand things in the ways un-corrupted by our
corrupt-in-sin flesh.
 
If it ever happens to you, David, then you will know what I
am speaking about. Until then, you are as Paul describes:
 
https://www.biblegateway.com/verse/en/1%20Corinthians%202%3A14
 
14 But the natural man receiveth not the things of the
Spirit of God: for they are foolishness unto him:
neither can he know them, because they are spiritually
discerned.
 
You lack the "eyes" to see, David, which is why you are blind.
I, too, was blind /BEFORE/ God drew me to His Son. And I was
just as adamant as you are that I was right, and that all of
the things of God are foolishness.
 
They are not foolishness. We are lost in sin, and because of
that the truth is kept from us. The only people who will come
to the truth are those God draws, and God only draws those who
He sees in His heart are of the kind of are seeking the truth,
even though they don't know what to seek for because of sin.
God overcomes them in their weakness and literally drags them
to the truth, and puts the words on their lips, "Jesus, forgive
my sin," so they can be saved.
 
When God draws someone ... they cannot resist Him. The change
is real as the spirit asserts itself over the flesh, and the
understanding giving input into man's soul from the spirit is
greater than that of the flesh. Its voice is louder, and it is
as Jesus said:
 
https://www.biblegateway.com/passage/?search=John+6%3A63&version=KJV
 
63 It is the spirit that quickeneth [makes one alive
eternally]; the flesh profiteth nothing: the words
that I speak unto you, they are spirit, and they
are life.
 
You call me blind because my teachings come from Jesus, and
His words are spirit, and they are life. You do not have a
spirit to discern Him, and therefore you cast me as having
had a nervous breakdown, or being on the receiving end of
some tragedy which caused my flesh-only mind to become cor-
rupted. You are unable to know that which those God saves
know. You do not have the spiritual eyes to see the truth.
 
You are blind, David, in that way.
 
--
Rick C. Hodgin
Christian Gollwitzer <auriocus@gmx.de>: Oct 01 08:52PM +0200

Am 01.10.18 um 12:28 schrieb Rick C. Hodgin:
>> without question.
 
> If you want to know the truth, Juha, look at the evidence.  It
> teaches you the truth.
 
He did. And he wrote his conclusion above: that the earth is several
billions of years old, as supported by scientists all around the world.
 
 
> nature of all life are uncovered.  It literally screams and cries
> out with the loudest voice imaginable:  CREATOR!  DESIGNER!  THIS
> WAS PURPOSEFULLY ENGINEERED!
 
A common misunderstanding. Just because something looks complicated, it
does not need to be "engineered". Who put the beautiful patterns in the
Mandelbrot fractal set? Nobody. They are not even there, your brain
infers them from a mathematical structure and thinks "oh, great designer"
 
 
> the DNA has to have
> come from somewhere, and no non-intelligent system has ever been
> observed in the laboratory to produce new information.
 
Wrong. Lookup genetic algorithms. The rules are extremely simple, yet
this mathematical simulation of evolution produces extremely complex
"well-designed" solutions to a given task. Even when you talk about
material evolution, short (self-reproducing) RNA sequences can be
produced by mixing chemicals and sending lightning strokes to them:

https://www.wired.com/2009/05/ribonucleotides/
 
It's just a matter of probability.
 
Christian
Christian Gollwitzer <auriocus@gmx.de>: Oct 01 08:55PM +0200

Am 01.10.18 um 20:04 schrieb Mr Flibble:
>> their religious sect before their brains have developed sufficiently
>> to think critically about what they're being taught.
 
> +1.
 
+1. It was known 2000 years ago and purposefully put into the religion:
 
https://biblehub.com/matthew/19-14.htm
 
Christian
Juha Nieminen <nospam@thanks.invalid>: Oct 01 07:11PM

> Dinosaurs (with man in history, hundreds of real-world
> documentation sources showing dinosaurs living with man):
 
Dinosaurs never co-existed with humans, but even if they did,
so what? What does that have anything to do with how old the
earth is, or how old fossils are?
 
The ancestors of the coelacanth that existed tens of millions of
years ago were very similar to the modern ones. The coelacanth
order still lives today. So what? Does that tell us something about
the age of the earth? No. Why should it?
 
Heck, just look at sharks. They haven't changed very much in
millions of years, yet they live to this day. So what? You don't
need to go to "dinosaurs co-existend with humans" conspiracy
theories. You can simply point to sharks, crocodiles and the
coelacanth for examples of clades that haven't changed much in
a very long time, and are still living today.
 
Creationists have this strange mistaken notion that "evolution
claims that dinosaurs went extint 65 million years ago". The
theory of evolution says no such thing. It takes absolutely no
stance on when some particular clade went or didn't go extinct.
It's not its field of study. (Paleontology is the field that
you are looking for, not evolution. And even if paleontology
is mistaken with a particular clade, it says absolutely nothing
about the age of the earth or the veracity of the theory of
evolution.)
 
> There is simply too much evidence regarding dinosaurs alone.
 
Evidence of what, exactly?
 
> It throws doubt on the whole evolution theory.
 
Dinosaurs have absolutely nothing to do with the theory of
evolution. Whatever you think you know about them is completely
irrelevant.
 
> This, of course, does
> not include the complexities found in DNA systems, which completely
> undoes the entirety of the evolution argument
 
Yeah, because you say so. You don't even understand what the theory
of evolution says. Prove me wrong, and give me an explanation of
what the theory is about.
 
> Information generation always comes from an intelligience
 
Even you don't believe that. Because if you did, then your God
would need a creator as well. After all, if all information must
come from an intelligence, where did your God, with all of your
information, come from? ("He has always existed" immediately
contradicts your original assertion, not to talk about you having
exactly zero evidence of it.)
 
> millions and billions of years could not have happened. Even
> our own Earth's motion, and our own moon teaches us by its motion,
> the truth.
 
Isn't it funny how only young earth creationists know "real science",
while no other scientist does?
 
> moon is slowly drifting away from the Earth. Run the math back-
> wards and you'll see what would've happened less than 100,000 yrs
> ago.
 
Clearly you didn't run those numbers yourself, but instead you just
believe the lies that creationists like Kent and Eric Hovind tell you.
 
Go ahead, and pluck the numbers into a calculator yourself, I dare you.
Horizon68 <horizon@horizon.com>: Oct 01 11:33AM -0700

Hello,
 
Read this:
 
 
My next software project is this:
 
I have just "invented" two random number generators
that are SplitMix64 and Mersenne Twister that are "scalable",
i mean that there Random "seed" is also scalable on manycores and
multicores NUMA systems. Both have passed the BigCrush tests.
 
 
 
Thank you,
Amine Moulay Ramdane.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 01 07:07PM +0100

I've added myself to my killfile as I can no longer stand most of what I
say: I'm just too egregious. I blame God.
 
--
 
Thank you,
Rick C. Hodgin
Paul <pepstein5@gmail.com>: Oct 02 03:52AM -0700

On Tuesday, October 2, 2018 at 10:22:52 AM UTC+1, Daniel wrote:
> setting numTrials to _any_ erroneous number, whether that be
> 2 or 2000000 or UINT_MAX or whatever. If you like, you
> can validate that numTrials is within a permissible range.
 
Daniel,
 
Thanks for your response.
I'm interested in the technique of validation.
With the approach in my OP,
I would write the following
Any feedback (even pointing out obvious carelessness)
would be helpful.
It has been tested as below but testing has been limited.
Since it's been copy-pasted from my compiler, apologies in advance
if the line returns look ugly.
 
Many thanks. It's been a very helpful newsgroup for me.
Paul
 
#include <exception>
#include <iostream>
 
class ValidInteger
{
 
static constexpr int min = 0;
static constexpr int max = 1000; // Suppose more than 1000 trials is unfeasible.
int NumTrials;
 
public:
ValidInteger(int);
bool operator< (const ValidInteger&) const;
ValidInteger& operator++();
};
 
ValidInteger::ValidInteger(int numTrials) : NumTrials(numTrials)
{
if(NumTrials < min)
throw(std::runtime_error("Underlying value too small"));
 
if(NumTrials > max)
throw(std::runtime_error("Underlying value too large"));
}
 
bool ValidInteger::operator<(const ValidInteger& rhs) const
{
return NumTrials < rhs.NumTrials;
}
 
ValidInteger& ValidInteger::operator++()
{
++NumTrials;
return *this;
}
 
void f()
{
std::cout << "\n f is called\n";
}
 
void perform_f(ValidInteger trialsNum)
{
 
for(ValidInteger i = 0; i <trialsNum; ++i)
f();
}
 
int main() // test valid and invalid cases
{
try{
perform_f(5);
perform_f(-5);
}
 
catch (const std::runtime_error& e)
{
std::cout << "\n" << e.what() << "\n";
}
}
David Brown <david.brown@hesbynett.no>: Oct 02 01:12PM +0200

On 02/10/18 12:52, Paul wrote:
> std::cout << "\n" << e.what() << "\n";
> }
> }
 
I would say that is over-engineering, unless your ValidInteger class
could be used in all sorts of other cases (in which case it should
probably be a template, and maybe a better name). Try this:
 
const int min_no_of_trials = 0;
const int max_no_of_trials = 1000;
 
void perform_f(int trialsNum) {
if (trialsNum < min_no_of_trials) {
throw(std::runtime_error("Too few trials");
}
if (trialsNum > max_no_of_trials) {
throw(std::runtime_error("Too many trials");
}
 
for (int i = 0; i < trialsNum; i++) {
f();
}
}
 
That puts the relevant logic where it makes sense.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Oct 02 11:39AM

On Tue, 2018-10-02, Paul wrote:
> which throws an exception in the constructor when a user tries to
> make the instantiation of the underlying integer positive.
 
> Is this what's done in practice?
 
No.
 
> If not, what is the standard solution?
 
Personally, I think it's the user's responsibility.
 
In general, I think it's very useful to create types which are locked
down in various ways. Instead of integers, I've used things like:
- Error counters which start at 0 and only support ++
- Numeric identifiers in various protocols (no arithmetics; different
protocol fields get distinct types).
- ...
 
I can't explain why, but I wouldn't do that here. Perhaps because it
has to be a runtime check, via an assertion.
 
(And perhaps because of what someone else wrote: where do you draw the
line? Is a billion tries ok?)
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Paul <pepstein5@gmail.com>: Oct 02 05:26AM -0700

On Tuesday, October 2, 2018 at 12:12:50 PM UTC+1, David Brown wrote:
> }
> }
 
> That puts the relevant logic where it makes sense.
 
Thanks David,
 
The original problem (before Daniel's response)
was avoiding applications allowing code saying things
like "Perform f() -2 times".
 
This opportunity is likely to be pervasive and that's why
I used my over-engineered solution.
I never thought of doing it with templates. I suppose the
reason is that we want to avoid lots of integer types becoming negative.
A template class, I think.
So instead of class ValidInteger, we could have
 
template<typename IntType>
class ValidRange{
// As previous code but int NumTrials; is
// replaced by IntType NumTrials;
// and things like ValidInteger::operator++ are replaced
//by ValidRange< IntType> :: operator++
 
 
}
 
Is that correct, and what you mean?
 
Thanks a lot. Glad you reminded me of the template solution.
 
Paul
Paul <pepstein5@gmail.com>: Oct 02 05:32AM -0700

On Tuesday, October 2, 2018 at 12:40:00 PM UTC+1, Jorgen Grahn wrote:
 
> (And perhaps because of what someone else wrote: where do you draw the
> line? Is a billion tries ok?)
 
> /Jorgen
 
Thanks, Jorgen.
So we want to lock down types in various ways.
We're interested in counting the number of times something is done.
So this starts at 0. Call this type TrialsCounter.
 
Now TrialsCounter can't represent a negative number of times.
So wouldn't the code for TrialsCounter be exactly like what I did?
 
I identified the need to lock down types, and I (and David) tried to
give an idea for doing so.
 
Paul
David Brown <david.brown@hesbynett.no>: Oct 02 02:42PM +0200

On 02/10/18 14:26, Paul wrote:
 
> The original problem (before Daniel's response)
> was avoiding applications allowing code saying things
> like "Perform f() -2 times".
 
My example is exactly as good at rejecting invalid values as yours, and
throws the same exceptions.
 
> This opportunity is likely to be pervasive and that's why
> I used my over-engineered solution.
 
Over-engineering is not good. Try to make the logic of the code clear.
In your case, there is a disconnect between the code that needs a
limited range, and the code that checks for the limits.
 
> //by ValidRange< IntType> :: operator++
 
> }
 
> Is that correct, and what you mean?
 
No.
 
I mean make ValidRange a template taking an int parameter, to form the
maximum allowed value. Templating on the type of integer is
over-engineering again.
 
Paavo Helde <myfirstname@osa.pri.ee>: Oct 02 04:16PM +0300

On 2.10.2018 10:58, Paul wrote:
> If a caller of perform_f erroneously sets numTrials to -1
> the number of trials performed is UINT_MAX which is unlikely to
> be what the caller wants.
 
For type conversions there is an option to use e.g. boost::numeric_cast
which can be routinely used instead of static_cast for prophylactic means:
 
#include <iostream>
#include <boost/cast.hpp>
#include <cstdint>
 
void f() {}
 
template<typename T>
void perform_f(T numTrials) {
const std::uint8_t n = boost::numeric_cast<std::uint8_t>(numTrials);
for (std::uint8_t i = 0; i < n; ++i) {
f();
}
}
 
int main() {
try {
std::cout << "Test A\n";
perform_f(25);
 
std::cout << "Test B\n";
perform_f(-2);
 
std::cout << "Test C\n";
perform_f(1000000);
 
} catch (const std::exception& e) {
std::cerr << e.what() << "\n";
return EXIT_FAILURE;
}
}
 
OUTPUT:
Test A
Test B
bad numeric conversion: negative overflow
James Kuyper <jameskuyper@alumni.caltech.edu>: Oct 02 08:04AM -0400

On 10/02/2018 05:45 AM, Ralf Goertz wrote:
> Am Sun, 30 Sep 2018 10:58:08 -0700
> schrieb Tim Rentsch <txr@alumni.caltech.edu>:
 
>> Ralf Goertz <me@myprovider.invalid> writes:
...
>> add, certainly in C, and I am pretty sure for C++.)
 
> But if they are separate types they need to overload the stream
> operators "<<" and ">>" in the same way the char types do, right?
 
What makes you think so? The relevant extractors for char, unsigned
char, and signed char are described in 27.7.2.2.3p11, while character
inserters get their own numbered section, 27.7.2.3.4. No mention is made
in either place of any extended integer type or size-named type.
 
As far as I can see, there's no requirement that any extractors or
inserters be provided for any extended integer type; 27.7.2.2.2 and
27.7.2.3.2 only describe arithmetic extractors and inserters for
standard types. Using the PRI/SCN macros defined in <cinttypes> or
<inttypes.h> with the formatted I/O routines declared in <cstdio> or
<stdio.h> are the only ways provided by C++ to directly input or output
any size-named types that are typedefed to extended integer types.
David Brown <david.brown@hesbynett.no>: Oct 02 01:01PM +0200

On 02/10/18 08:44, Chris M. Thomasson wrote:
> order. The atomics should not be optimized away. They better not be, or
> else it would ruin things. It would seem to mess around with other
> algorithms as well.
 
The atomic loads and stores can be optimised away. But it is rare that
the compiler could prove that this is safe, so it is unlikely to do so.
In particular, they can be optimised or re-arranged if the compiler can
be sure that no other thread can see them. And if they are "relaxed"
operations, there is no synchronisation on the loads or stores - all the
compiler must guarantee is that no thread ever sees a half-way read or
write - it's either all or nothing. For object sizes that the cpu can
read and write as a single unit, a relaxed load or store can be
implemented as a normal load or store. However, the requirement for
sequencing between threads means that these can't be re-ordered or
eliminated unless the compiler knows that no other thread could access
them. You could only get this knowledge for local atomic variables that
don't "escape" in any way - such restricted cases would be almost
entirely useless for atomics. So it is likely that compilers never
bother to optimise them away, and treat them pretty much as "volatile".
 
However, race conditions are always undefined behaviour. And relying on
the behaviour of undefined behaviour is never a good idea.
 
If the compiler can figure out that you definitely always have a race
condition, it could use that knowledge to optimise away the code. I
think it is highly unlikely for it to see such cases, but it is still a
bad idea to rely on it.
 
People have tried to use undefined behaviour to give "random" data
before - I know of a well-publicised case where uninitialised local
variables were use to give "more entropy" to some key data. It always
ends in tears - do /not/ do this.
 
 
 
> All of the atomic loads and stores in an algorithm should be intact,
> damn it.
 
You can only rely on the compiler to give you the code you want when you
write the code in correct C or C++. If you write code with errors, such
as race conditions, you /might/ get what you expect - you might get
something entirely different.
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Oct 02 12:45PM +0100

On Mon, 1 Oct 2018 23:44:24 -0700
> > vague warnings about friend functions and do not work anymore.
 
> All of the atomic loads and stores in an algorithm should be intact,
> damn it.
 
So far as I understand your code, the "racer" function is inaptly named
in the C++ sense because it modifies an atomic variable with relaxed
memory ordering. This is indeed unsynchronized with no "happens before"
relationships, and the outcome will be indeterminate; but in C++
standardeze that does not of itself generate a "data race" or undefined
behaviour.
 
In C++ standardeze:
 
The execution of a program contains a data race if it contains two
potentially concurrent conflicting actions, at least one of which is
not atomic, and neither happens before the other, except for the
special case for signal handlers described below. Any such data race
results in undefined behavior.
 
All your concurrent actions appear to be on a single atomic variable
and are therefore atomic. So although the second leg of the test for a
"data race" is met, the first leg is not. Note that this is different
from what most people would call a "data race" in the programmatic
sense: most people would say that any program which does not establish
the correct "happens before" relationships is "racy". But that does not
of itself give rise to undefined behaviour.
 
Since your atomic is instantiated for unsigned int, any compiler on any
platform you come across will translate the stores and loads with
relaxed memory ordering into plain stores and loads. But I do not
believe that then entitles the compiler to mess around with your
code further on the grounds of undefined behaviour. If your shared
variable were a plain unsigned int it could do so. If is of type
std::atomic<unsigned int> then not, as I read it.
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: