Friday, November 23, 2018

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

"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 16 08:33AM -0800

On Friday, November 16, 2018 at 11:23:12 AM UTC-5, Rick C. Hodgin wrote:
> If you want to know the truth ... pursue it. If you want to go
> on asserting what you think you already know ... there is then
> no hope for you whatsoever. The choice is yours.
 
Note: This pursuit of truth is not something you can accomplish
on your own, but it begins with the attitude in your heart. You
have to get to the place where you're able to say truthfully,
"Okay, I may be wrong in what I think today. If I am wrong, then
I do want to know the truth."
 
If you can get to that place, then God will do the rest. He will
bring you to truth, and truth to you. It's the only way you will
find it, because in sin in your flesh-only nature, you cannot
know truth, but only be deceived. It takes an act of God to over-
ride your flesh, to pour out His Holy Spirit drawing, to lead you
in ways you cannot lead yourself, so you can come to know the truth
and be saved.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 16 05:37AM -0800

On Thursday, November 15, 2018 at 11:57:28 PM UTC-5, Chris M. Thomasson wrote:
> the sentient intelligent inhabitants that He created anyway. God has
> experienced being a Human on Earth within the physical realm. Did God do
> the same thing for other planets in the creation?
 
It's never been explained in scripture. What God has revealed
is there are three Heavens. The first is the air. The second
is what we see in space (the stars, galaxies, and beyond). The
third is not seen, but is the dominion of God, a paradise.
 
Paul describes going there and that he heard things illegal for
a man to talk about.
 
What we have here in this physical world is the merest inkling
fraction of what God's creation is. And He (God) offers each
of us the ability to partake in that universe beyond what we
know today, a place existing outside of time, as we see multiple
references in scripture to people being taken out of time, or
angels appearing and describing things out of time, etc.
 
Jesus is the doorway. He takes away our sin, restoring us to
that eternal Kingdom, giving us eternal life, making it possible
for us to partake of God's true domain in the third Heaven.
 
(1) Sinners forgiven by Jesus, go on to Heaven.
(2) Sinners unforgiven, enter into Hell.
 
There is a solid chasm created by God, designed to separate all
that is of His Kingdom of truth, and all that is embracing and
holding on to falseness. That chasm is the division between
Heaven and Hell. No one in Heaven will ever enter into Hell,
and no one in Hell will ever escape and enter into Heaven.
 
It is a literal eternal prison, holding only those who refuse
to accept truth, who hold onto falseness ahead of truth, who
would only believe the lies of the enemy and not approach the
truth of God to receive Him, salvation for their soul, the
release of sin's condemnation upon their life, etc.
 
Each person sends themselves to Hell. God has done everything
to make it possible for everyone to have eternal life. He's
made Jesus' sacrifice available to all ... and it's free for
the asking.
 
A person has to work very very hard to enter into Hell given
all the saving provisions God has put before them in their life.
And each person will self-condemn their own soul in God's final
court on Judgment Day, when the books are opened which recorded
the events of our lives.
 
For the sinner saved by grace, everything's been blotted out
that could condemn us. The entries were put on Jesus' list,
and He paid the price of our sin in our place. For the sinner
not saved, every sin they've committed remains in full force,
in written form, recorded accurately, from their entire life.
The secret things. The hidden things. The things you thought
nobody knew about ... it's all there, and it will be read aloud
in court before all as part of the permanent record as to why
your soul is cast into the eternal lake of fire from which there
is no escape, no parole, no anything except pain and angst and
eternal torment.
 
The choice is each of ours today. God has made salvation avail-
able to all today for free. Simply ask Jesus to forgive your
sin, and take up your own personal metaphoric cross and follow
Him in this world.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 16 08:22AM -0800

On Friday, November 16, 2018 at 10:24:52 AM UTC-5, Mr Flibble wrote:
> the 100th Cycle that what is written in the 100th Cycle is true. The
> 100th Cycle clearly states that the book known as "The Bible (Abrahamic
> Edition)" is pet toy sku number #42666.
 
Your thinking is natural for a person, Leigh. What it does not
possess is an acknowledgement of absolute truth, which is God
originating real information that is not part of a deception.
 
You look at things only through eyes that see the ability to
lie / cheat / deceive. You do not acknowledge the possibility
that God has preserved His written word for our edification
and benefit. You do not see that a God of truth and power could
actually exist. You only see what sin allows you to see, which
is the full-on, widespread, pervasive corruption seen here in
this world (all of which is the result of sin only, and is not
part of God's plan for mankind, but the side-effect of man's
sin and rebellion producing this effect here on this Earth).
 
-----
No one can teach you to trust in God. If you cannot see His hand
at work in the miracle of birth, in the complex nature of the
many physics theories, of chemistry, of the arrangement of the
many species in nature, the diversity of life, yet its many many
similarities, etc... then it's not for you to know the things of
God, because all of the knowledge of God is gifted to those who
will be saved by God, so they can know the truth, and that truth
will make them free. The rest will never be able to have any
knowledge of God, because such knowledge comes from the spirit,
and is not of the flesh. And because of sin our spirit is dead,
and we cannot know the things of the spirit without God directly
intervening in our existence to "prime us" to be led toward His
Son where we ask forgiveness, and then receive our own spirit
and are saved.
 
If you want to know the truth ... pursue it. If you want to go
on asserting what you think you already know ... there is then
no hope for you whatsoever. The choice is yours.
 
--
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 16 08:04PM

On 16/11/2018 18:36, Rick C. Hodgin wrote:
> On Friday, November 16, 2018 at 11:42:03 AM UTC-5, Mr Flibble wrote:
>> [snip tl;dr] ...
 
[snip]
 
Anti-gravity shoes, mate.
 
/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."
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 16 04:41PM

On 16/11/2018 16:22, Rick C. Hodgin wrote:
 
[snip tl;dr]
 
Anti-gravity shoes, mate.
 
/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."
"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Nov 16 06:03PM -0800

On 11/14/2018 4:02 PM, Mr Flibble wrote:
> eyes) and they continue to abduct and experiment on people.  People
> think they are demons when in fact they are inter-dimensional beings
> (the word "demon" comes from the word "dimension").
 
I enjoy thinking of such things from time to time. I do not know if
Earth is in some database on another world. Fun to ponder.
 
I wonder if "The Grays" have many humans in experimental cloning farms.
 
Ouch. It sure sounds like the grays are evil, and have no concept of
ethics. They will perform radically invasive experiments on anything
they encounter.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 16 02:24PM

On 16/11/2018 13:37, Rick C. Hodgin wrote:
> is there are three Heavens. The first is the air. The second
> is what we see in space (the stars, galaxies, and beyond). The
> third is not seen, but is the dominion of God, a paradise.
 
The problem is, Rick, that this scripture you mention is, as I have stated
already, only half the story: The Bible is a disinformation campaign
designed by the Nordic Aliens to retard our mental and technological
development as the Nordics like to keep us as pets and nobody wants an
independently minded pet that refuses sexual favours.
 
You can see for yourself that what I say is true by referring to the 100th
Cycle (Issue 14) Buttered Scone (Sin) Manifest (Virgo Cluster Edition).
 
[snip tl;dr]
 
/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."
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 16 10:36AM -0800

On Friday, November 16, 2018 at 11:42:03 AM UTC-5, Mr Flibble wrote:
> [snip tl;dr] ...
 
It's like that movie by Kevin Smith where there's one of those
3D images and if you stare at it and your eyes adjust you can
see what it is. And there's this guy who's been there staring
at it all day and cannot see it. But at one point a little boy
walks up, stares for just a few seconds, identifies what it is,
smiles, laughs, and then walks off.
 
There are some who will never come to know Christ. Others will.
The message of salvation is given for those who will, and it is
given as evidence against those who will not.
 
Every person is given the opportunity to be a part of God's
eternal Kingdom. All who receive His free offer / gift of sal-
vation will be a part of it. The rest will not.
 
-----
Ponder these things, Leigh. Consider you may be wrong in your
current thinking. Ask God to lead you to the truth. Ask Him
to uncover your eyes if they be covered, and to open your mind
if it be closed. He will do this, if you are truly seeking.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 16 06:49AM -0800

On Friday, November 16, 2018 at 9:24:12 AM UTC-5, Mr Flibble wrote:
> > third is not seen, but is the dominion of God, a paradise.
 
> The problem is, Rick, that this scripture you mention is, as I have stated
> already, only half the story: The Bible is a disinformation campaign...
 
It isn't. You're being deceived into believing that by the
enemy's of God who desire to keep you away from that future
God's offering you through His own sacrifice in your place,
to set you free from the judgment of sin.
 
I can only offer you the truth, Leigh. I cannot make you
believe it, nor is it my job to do so. I tell you the way
things are ... I'm not responsible for your response to it.
 
--
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 16 03:24PM

On 16/11/2018 14:49, Rick C. Hodgin wrote:
> enemy's of God who desire to keep you away from that future
> God's offering you through His own sacrifice in your place,
> to set you free from the judgment of sin.
 
No, you are mistaken. The 100th Cycle is true because it is written in
the 100th Cycle that what is written in the 100th Cycle is true. The
100th Cycle clearly states that the book known as "The Bible (Abrahamic
Edition)" is pet toy sku number #42666.
 
 
> I can only offer you the truth, Leigh. I cannot make you
> believe it, nor is it my job to do so. I tell you the way
> things are ... I'm not responsible for your response to it.
 
You cannot offer me any truth whilst you remain blinded by pet toys. I
suggest you read the Buttered Scone (Sin) Manifest for yourself so you can
finally see the truth.
 
/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."
Ben Bacarisse <ben.usenet@bsb.me.uk>: Nov 16 01:53AM


>> return 1 for ipow(0, 0), wouldn't you?
 
> Why? Zero raised to any power results in zero.
> Why is that argument less valid than yours?
 
Beause of the context where ipow would be used. I listed some but I
can't think of any where ipow(0, 0) == 0 is more useful. What sort of
code are you considering?
 
--
Ben.
jameskuyper@alumni.caltech.edu: Nov 16 06:32AM -0800

On Friday, November 16, 2018 at 7:12:08 AM UTC-5, Juha Nieminen wrote:
> for (int i = 1; i < n; ++i) result *= x;
 
> which saves one iteration, and which would give you 0 for the case
> that both x and n are 0.
 
That will give the wrong result for any value of x other than 1
(except for 0, where the "right" result is not definable).
Juha Nieminen <nospam@thanks.invalid>: Nov 16 12:11PM


> int result=1;
> for (int i=0; i<n; i++) result*=x;
 
> This will produce 0^0 = 1 in a "natural" way.
 
On the other hand, you could optimize the above a bit and say:
 
int result = x
for (int i = 1; i < n; ++i) result *= x;
 
which saves one iteration, and which would give you 0 for the case
that both x and n are 0.
Geoff <geoff@invalid.invalid>: Nov 15 08:27PM -0800

On Thu, 15 Nov 2018 06:31:18 -0800 (PST),
>those decisions were made entirely at random, or by someone
>unfamiliar with the fact that mathematically, the value of 0^0 is
>undefined.
 
What did Whitehead and Russell have to say about it in Principia?
Paavo Helde <myfirstname@osa.pri.ee>: Nov 16 03:04PM +0200

On 16.11.2018 14:11, Juha Nieminen wrote:
> for (int i = 1; i < n; ++i) result *= x;
 
> which saves one iteration, and which would give you 0 for the case
> that both x and n are 0.
 
This would produce a wrong value x^0 for all x>1.
Paavo Helde <myfirstname@osa.pri.ee>: Nov 15 10:13PM +0200

On 15.11.2018 18:33, Manfred wrote:
> care.
> IME such special cases are best avoided, and typically this can be
> achieved by a proper rearrangement of the algorithm.
 
Agreed.
 
On another tangent, when calculating x^n, it might make sense to use an
optimized function for small enough integer arguments, e.g.
 
int result=1;
for (int i=0; i<n; i++) result*=x;
 
This will produce 0^0 = 1 in a "natural" way. On the other hand, there
is not much point to provide a special check or branch for 0^n as this
would apply only for invalid/degenerate data which should not be a
normal usage case.
 
Not sure if this says anything about anything.
woodbrian77@gmail.com: Nov 17 02:07PM -0800

On Saturday, November 17, 2018 at 3:20:47 PM UTC-6, Alf P. Steinbach wrote:
 
> That's very wrong, pure disinformation.
 
> A function defined inside a class is implicitly `inline`, yes.
 
> However, a freestanding function template is not, and a `constexpr` is not.
 
Well, I have some freestanding function templates that aren't
marked as inline and neither gcc 8.2 or clang 7.0 say anything
about that. I'm not sure it's a problem.
 
> > led to a bit smaller text segments.
 
> > I'm encouraged by these events and ask for further review of my software.
 
> Hm, encouraged by disinformation that Seems To Work™.
 
I don't know if the author intended to muddy the waters.
At any rate, it was helpful to me in that some of it was
accurate.
 
 
Brian
woodbrian77@gmail.com: Nov 17 12:58PM -0800

I was until today laboring under the idea that I needed to
mark all non-template functions in header files as inline.
Then I read on reddit/learnprogramming:
 
"Almost all templates and constexpr values are implicitly inline. Also any function defined inside a class."
 
It's the last part about functions defined inside a class that
I didn't know or had forgotten. I've now updated my software:
https://github.com/Ebenezer-group/onwards
 
and tested that this is kosher with both gcc and clang. Removing
the superfluous inline keywords didn't make any difference to
the size of the text segments for gcc 8.2, but for clang 7.0 it
led to a bit smaller text segments.
 
I'm encouraged by these events and ask for further review of my software.
 
 
Brian
Ebenezer Enterprises - "The L-RD is near to the brokenhearted; He saves the contrite in spirit. Many are the afflictions of the righteous, but the L-RD delivers him from them all." Psalms 34:18-19
http://webEbenezer.net
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 17 10:20PM +0100

> mark all non-template functions in header files as inline.
> Then I read on reddit/learnprogramming:
 
> "Almost all templates and constexpr values are implicitly inline. Also any function defined inside a class."
 
That's very wrong, pure disinformation.
 
A function defined inside a class is implicitly `inline`, yes.
 
However, a freestanding function template is not, and a `constexpr` is not.
 
If you fully specialize a function template you don't get an `inline`
function, unless you add the keyword `inline`. So you can easily run
into multiple definition errors. It depends on what you do.
 
If you take the address of a not explicitly inlined `constexpr` value in
two different translation units, you get two different addresses. If you
do that with an `inline` value you get the same address.
 
 
> the size of the text segments for gcc 8.2, but for clang 7.0 it
> led to a bit smaller text segments.
 
> I'm encouraged by these events and ask for further review of my software.
 
Hm, encouraged by disinformation that Seems To Work™.
 
 
Cheers!,
 
- Alf
"Öö Tiib" <ootiib@hot.ee>: Nov 16 07:04AM -0800

On Friday, 16 November 2018 12:23:16 UTC+2, Paul wrote:
> What does the compiler feedback say about whether the computations
> are skipped in the way described above?
> Many thanks for your comments, and for all help previously given.
 
Unoptimized code is specially generated bad performing
one-to-one translation. That is for to make it possible to step
through our algorithm logic with debugger. Additionally the
compiler or library implementation may instrument code that
is built for debugging with run-time checks that standard
does not require. Such thing does not perform in any way
similarly to actual product so there are no point to measure
performance of debug builds.
 
Optimizer however tries to achieve maximally well performing
results. So part of the calculations done with constant values
it can do compile time. Calculations done in loop with same,
unchanged arguments it may do once and reuse the result.
Calculations whose results cause no side effects it may leave
not done and so on. So naive performance tests of optimized
builds can also give nonsensical results.
 
I see such optimized main of yours in godbolt.org:

main:
xor eax, eax
ret
David Brown <david.brown@hesbynett.no>: Nov 16 01:44PM +0100

On 16/11/18 11:23, Paul wrote:
> I attempted to test this theory with Godbolt's compiler explorer.
> I have no formal education in assembly or computing more generally,
> so the feedback is cryptic.
 
The code below looks like you did not have optimisations enabled. You
can put whatever flags you want in the command line on godbolt.org.
Useful ones include :
 
-x c // For C compilation rather than C++
-std=gnu++17 // For gcc extended C++17
-std=c++17 // For standard C++17
-std=gnu11 // For gcc extended C11 (with -x c)
 
-Wpedantic // For warnings about non-standard C or C++
 
-O1 or -O2 // Basic optimisation
-Wall -Wextra // Common warnings
 
-m32 // Generate 32-bit code instead of 64-bit
 
Another good trick when looking at the code is to avoid complicated
library code. For example, if you want to see the code for calculating
"foo(x) + bar(x)", don't try to pass the result to std::cout or printf.
The important stuff will get lost in the details. Rather, write a
simple function "int foobar(x) { return foo(x) + bar(x); }" so that you
can look at the code for that function.
Ben Bacarisse <ben.usenet@bsb.me.uk>: Nov 16 11:43AM

> generates by calling basicPopcount, many of the basicPopcount calls should
> simply be skipped because the compiler has worked out that the computation
> would be pointless.
 
Yup. That's what happens with, for example, with g++ 8.2.0 with -O1 and
above.
 
> Compiler is x86-64 gcc 8.2
> What does the compiler feedback say about whether the computations
> are skipped in the way described above?
 
No. What you show has a main function that loops calling your
basicPopcount function:
 
> mov eax, 0
> leave
> ret
 
Maybe you did not request optimisation?
 
A couple of points about the function itself...
 
> ++count;
 
> return count;
> }
 
The term "overflow" is a little odd here. There are two things to worry
about. The first is shifting a 1 bit into the sign position and you've
dealt with that but using 1u. The second thing is not really "overflow"
per se. Shifting by the width of the (promoted) left-hand operand is
undefined so the only way to give your loop defined behaviour is use a
type that is wider than int. Unfortunately, unsigned long long int is
not guaranteed to be wider -- you might find some odd implementation
that has decided to make all the int types the same width.
 
There are various ways round this but I won't give any right now since I
get the impression you like to work things out for yourself.
 
Finally, you *do* have a theoretical overflow problem here:
 
> for(int i = 0; i < 10 * 1000 * 1000; ++i)
> basicPopcount(i);
> }
 
10 * 1000 * 1000 is larger than the smallest permitted value for INT_MAX
(or, in more C++ terms, std::numeric_limits<int>::max()). You may never
come across an implementation with that narrow an int, but you could
impress an interviewer by showing that you are aware of the issue.
 
--
Ben.
Paul <pepstein5@gmail.com>: Nov 16 02:23AM -0800

I posted the below code on another thread.
A respondent said that the code should be "optimized away" by a good compiler.
Presumably, this means that because basicPopcount has no side effects,
and because main() doesn't do anything with the local variables it
generates by calling basicPopcount, many of the basicPopcount calls should
simply be skipped because the compiler has worked out that the computation
would be pointless.
I attempted to test this theory with Godbolt's compiler explorer.
I have no formal education in assembly or computing more generally,
so the feedback is cryptic.
Complete code and compiler explorer data are copy-pasted below.
Compiler is x86-64 gcc 8.2
What does the compiler feedback say about whether the computations
are skipped in the way described above?
Many thanks for your comments, and for all help previously given.
Paul
 
 
#include<iostream>
int basicPopcount(int x)
{
int count = 0;
int place = 0;
// An overflow bug can arise in this method for large values of x
// So make sure types are large enough
while(1ull << place <= x)
if(1ull << place++ & x)
++count;
 
return count;
}
 
int main()
{
for(int i = 0; i < 10 * 1000 * 1000; ++i)
basicPopcount(i);
}
 
 
basicPopcount(int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-20], edi
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 0
.L4:
mov eax, DWORD PTR [rbp-8]
mov edx, 1
mov ecx, eax
sal rdx, cl
mov eax, DWORD PTR [rbp-20]
cdqe
cmp rdx, rax
ja .L2
mov eax, DWORD PTR [rbp-20]
movsx rsi, eax
mov eax, DWORD PTR [rbp-8]
lea edx, [rax+1]
mov DWORD PTR [rbp-8], edx
mov ecx, eax
shr rsi, cl
mov rax, rsi
and eax, 1
test rax, rax
setne al
test al, al
je .L4
add DWORD PTR [rbp-4], 1
jmp .L4
.L2:
mov eax, DWORD PTR [rbp-4]
pop rbp
ret
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 0
.L8:
cmp DWORD PTR [rbp-4], 9999999
jg .L7
mov eax, DWORD PTR [rbp-4]
mov edi, eax
call basicPopcount(int)
add DWORD PTR [rbp-4], 1
jmp .L8
.L7:
mov eax, 0
leave
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L12
cmp DWORD PTR [rbp-8], 65535
jne .L12
mov edi, OFFSET FLAT:_ZStL8__ioinit
call std::ios_base::Init::Init() [complete object constructor]
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:_ZStL8__ioinit
mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
call __cxa_atexit
.L12:
nop
leave
ret
_GLOBAL__sub_I_basicPopcount(int):
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
Bo Persson <bop@gmb.dk>: Nov 17 07:43PM +0100

On 2018-11-17 11:55, Paul wrote:
> {
> std::cout << (unsigned int(230));
> }
 
Check the rules for "Explicit type conversion"
 
https://en.cppreference.com/w/cpp/language/explicit_cast
 
In particular case 2), which states:
 
"The functional cast expression consists of a simple type specifier or a
typedef specifier (in other words, a single-word type name: unsigned
int(expression) or int*(expression) are not valid)[...]"
 
 
Bo Persson
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 17 09:20PM +0100

On 17.11.2018 11:55, Paul wrote:
> compile without needing to try it.
> Why does the compiler not recognise unsigned int as the type "unsigned"
> in the below context?
 
Because C++ got the botched declaration syntax from C, and use rules
that don't accommodate that syntax.
 
One might say that the message is, don't use C declaration syntax except
to the degree that it suits C++.
 
The source code formatting impact of that is:
 
* One thing declared per declaration.
* Focus on types, with type builders like `*` viewed as basic type
modifiers instead of thing type modifiers: space between type and thing.
* Declarations as close to first use as practically possible.
 
 
> {
> std::cout << (unsigned int(230));
> }
 
The simplest remedy is to just omit the word `int`, which is implicit
anyway:
 
cout << unsigned( V )
 
Another remedy is to use a C++ named cast:
 
cout << static_cast<unsigned int>( V )
 
Or, third remedy, you can define
 
template< class T > Type_ = T;
 
... and then write
 
cout << Type_<unsigned int>( V )
 
The last approach also lets you use prefix `const` wherever you wish, so
that you can do that /consistently/, which I think is great.
 
 
Cheers & hth.,
 
- Alf
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: