Sunday, November 13, 2016

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

Bob Langelaan <bobl0456@gmail.com>: Nov 13 11:04AM -0800

I am helping a student with an assignment (not writing the solution for him!!!).
 
I can implement a doubly linked list in my sleep but when it comes to some forms of input I'm not nearly as strong. I'm just looking for hint(s) here and NOT SOLUTIONS.
 
The assignment specifies that each line of input will basically look like this:
 
nnnnn nnnnnn string string <newline>
<newline>
nnnnn nnnnnn string string <newline>
<newline>
...
 
- Note - nnnnn simply represents an integer value. The strings will not contain any white-space.
 
But input needs to handle error cases:
 
nnnnn <newline> <-- missing last 3 values
 
nnnnn nnnnn <newline> <-- missing last 2 string values
 
nnnnn nnnnn string <newline> <-- missing last string value
 
nnnnn nnnnn string string <extra_unwanted_values> <newline>
 
This is the first assignment for this class and their first use of the string class and therefore I would be surprised if they are required to use istringstream as part of their solution. And another possibility is to use a function like getchar() to read in each character, one by one, and manufacture the int and string values character by character.
 
My question is there a better/easier way? This "better/easier way" would, I assume, need to be aware when a '\n' is encountered in the input stream.
 
Thanks in advance :)
Vir Campestris <vir.campestris@invalid.invalid>: Nov 13 09:42PM

On 13/11/2016 19:04, Bob Langelaan wrote:
> My question is there a better/easier way? This "better/easier way" would, I assume, need to be aware when a '\n' is encountered in the input stream.
 
getline and sscanf?
 
I think perhaps they _should_ be taught streams now. They'll probably
need it a lot in their early careers, and it's better than the bad
habits people like me have.
 
Andy
woodbrian77@gmail.com: Nov 13 02:59PM -0800

On Sunday, November 13, 2016 at 3:42:38 PM UTC-6, Vir Campestris wrote:
 
> I think perhaps they _should_ be taught streams now. They'll probably
> need it a lot in their early careers, and it's better than the bad
> habits people like me have.
 
Streams are untidy.
I use getline sometimes.
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
ram@zedat.fu-berlin.de (Stefan Ram): Nov 13 09:32PM

>nnnnn nnnnnn string string <newline>
 
I know, I'll use regular expressions.
 
#include <iostream>
#include <istream>
#include <ostream>
#include <regex>
#include <sstream>
#include <string>
 
void ok(){ ::std::cerr << "ok" << '\n'; }
 
void bad
( ::std::string const & e )
{ ::std::cerr << "bad " << e << '\n'; exit( 99 ); }
 
void chk
( ::std::string const & s,
::std::string const & p, ::std::string const & e )
{ if( !::std::regex_search( s, ::std::regex( p.c_str() ) ))bad( e ); }
 
void expect_that_line( ::std::basic_istream<char> & i )
{ ::std::string s; ::std::getline( i, s );
chk( s, R"(^\d+)", "0" );
chk( s, R"(^\d+ )", "1" );
chk( s, R"(^\d+ \d+)", "2" );
chk( s, R"(^\d+ \d+ )", "3" );
chk( s, R"(^\d+ \d+ [^ ]*)", "4" );
chk( s, R"(^\d+ \d+ [^ ]* )", "5" );
chk( s, R"(^\d+ \d+ [^ ]* [^ ]*)", "5" );
chk( s, R"(^\d+ \d+ [^ ]* [^ ]* )", "6" );
chk( s, R"(^\d+ \d+ [^ ]* [^ ]* $)", "7" );
ok(); }
 
int main()
{ ::std::stringstream s( "1 23 a b \n" );
expect_that_line( s ); }
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 12 06:02PM -0800

Have an Encounter with Jesus today
 
There's a new TV series on Pureflix. It is a representation of how
Jesus interacts with people in their lives. He calls out to them in
their life things and situations. No matter what bad things is going
on around you, He's always there trying to lead you to forgiveness in
Him, and to all of the things a heart filled with love would do for
those around you:
 
The Encounter 2010 Movie
The Encounter 2016 TV Series
http://www.pureflix.com
 
And go to church on Sunday. Call your closest Christian family
member, friend, co-worker, classmate, and ask them to take you to
church tomorrow. Ask them the questions you have about Jesus, and
why men and women like me (like us) find comfort in being forgiven
for our sin, and in trusting in the Lord.
 
I love you. But Jesus loves you more. Watch that The Encounter TV
series and see how He calls out to people in their lives and all of
the things we get ourselves tangled up in. He's like a GPS, always
pointing you to the correct destination, even if you make a wrong
turn here or there.
 
Best regards,
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 13 03:08AM -0600

> the things we get ourselves tangled up in. He's like a GPS, always
> pointing you to the correct destination, even if you make a wrong
> turn here or there.
 
In his imaginary conversation with God, Fry says he would tell him: "How
dare you create a world in 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 which is so full of injustice
and pain?"
 
Pressed by Byrne over how he would react if he was locked outside the
pearly gates, Fry says: "I would say: 'bone cancer in children? What's that
about?'
 
"Because the God who created this universe, if it was created by God, is
quite clearly a maniac, utter maniac. Totally selfish. We have to spend our
life on our knees thanking him?! What kind of god would do that?"
 
On how to explain the wonders of the world, Fry then launches an another
attack on all seeing, all knowing God creator.
 
"Yes, the world is very splendid but it also has in it insects whose whole
lifecycle is to burrow into the eyes of children and make them blind. They
eat outwards from the eyes. Why? Why did you do that to us? You could
easily have made a creation in which that didn't exist. It is simply not
acceptable.
 
"It's perfectly apparent that he is monstrous. Utterly monstrous and
deserves no respect whatsoever. The moment you banish him, life becomes
simpler, purer, cleaner, more worth living in my opinion."
Melzzzzz <mel@zzzzz.com>: Nov 13 10:39AM +0100

On Sat, 12 Nov 2016 18:02:56 -0800 (PST)
 
> I love you. But Jesus loves you more.
 
> Best regards,
> Rick C. Hodgin
 
I wonder how would you preach if you being born in Saudi Arabia as
muslim...
Probably you would shout Allahu Akbar...
 
--
press any key to continue or any other to quit
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 13 03:56AM -0800

Mr. Flibble wrote:
> and deserves no respect whatsoever. The moment you banish
> him, life becomes simpler, purer, cleaner, more worth living
> in my opinion."
 
Sin is the cause of all forms of malady, including death. Jesus came to
take sin away, freeing us from all malady, including death.
 
http://biblehub.com/kjv/2_corinthians/5.htm
21 For he hath made him to be sin for us,
who knew no sin; that we might be made
the righteousness of God in him.
 
http://biblehub.com/kjv/1_john/3.htm
14 We know that we have passed from death
unto life, because we love the brethren. He
that loveth not his brother abideth in death.
15 Whosoever hateth his brother is a murderer:
and ye know that no murderer hath eternal
life abiding in him.
16 Hereby perceive we the love of God, because
he laid down his life for us: and we ought to
lay down our lives for the brethren.
 
God honors our choices, even if they lead to eternal damnation in Hell.
He works within our choices, always reaching out to save those who
will be saved. And those who are saved find a real inner peace even
in the midst of this world's turmoil. The Bible calls it, "The peace
that surpasses all understanding." It is a worldly deposit of a hint
of His Kingdom's manner. It's why Satan tries to keep people from
coming to Jesus, because if they go to Him they are saved.
 
Watch the TV series and the movie. You'll come to understand by
example. The Encounter 2010 describes it perfectly.
 
Best regards,
Rick C. Hodgin
leigh.v.johnston@googlemail.com: Nov 13 05:14AM -0800

In his imaginary conversation with God, Fry says he would tell him: "How
dare you create a world in 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 which is so full of injustice
and pain?"
 
Pressed by Byrne over how he would react if he was locked outside the
pearly gates, Fry says: "I would say: 'bone cancer in children? What's that
about?'
 
"Because the God who created this universe, if it was created by God, is
quite clearly a maniac, utter maniac. Totally selfish. We have to spend our
life on our knees thanking him?! What kind of god would do that?"
 
On how to explain the wonders of the world, Fry then launches an another
attack on all seeing, all knowing God creator.
 
"Yes, the world is very splendid but it also has in it insects whose whole
lifecycle is to burrow into the eyes of children and make them blind. They
eat outwards from the eyes. Why? Why did you do that to us? You could
easily have made a creation in which that didn't exist. It is simply not
acceptable.
 
"It's perfectly apparent that he is monstrous. Utterly monstrous and
deserves no respect whatsoever. The moment you banish him, life becomes
simpler, purer, cleaner, more worth living in my opinion."
bitrex <bitrex@de.lete.earthlink.net>: Nov 13 08:55AM -0500

On 11/12/2016 09:02 PM, Rick C. Hodgin wrote:
 
> Have an Encounter with Jesus today
 
Okay, if you insist, but I don't want to pay more than $20 for it. I'm
not into anything too crazy.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Nov 13 06:25AM -0800

Mr. Flibble wrote:
> [snip]
 
It is you who gets to determine where you will spend eternity, Leigh.
You are in control. You are the master. Jesus did the hard part of
dying to sin for all who will believe. He now gives forgiveness and
eternal life to all who will receive it. And because He gave you free
will, you are now the determiner of your fate. Jesus only warns you
where you're currently heading, and that if you ask Him to forgive you
He will.
 
It's all you, Leigh. Your choice. Make it a good one.
 
Best regards,
Rick C. Hodgin
leigh.v.johnston@googlemail.com: Nov 13 10:18AM -0800

On Sunday, November 13, 2016 at 2:25:47 PM UTC, Rick C. Hodgin wrote:
> where you're currently heading, and that if you ask Him to forgive you
> He will.
 
> It's all you, Leigh. Your choice. Make it a good one.
 
In his imaginary conversation with God, Fry says he would tell him: "How
dare you create a world in 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 which is so full of injustice
and pain?"
 
Pressed by Byrne over how he would react if he was locked outside the
pearly gates, Fry says: "I would say: 'bone cancer in children? What's that
about?'
 
"Because the God who created this universe, if it was created by God, is
quite clearly a maniac, utter maniac. Totally selfish. We have to spend our
life on our knees thanking him?! What kind of god would do that?"
 
On how to explain the wonders of the world, Fry then launches an another
attack on all seeing, all knowing God creator.
 
"Yes, the world is very splendid but it also has in it insects whose whole
lifecycle is to burrow into the eyes of children and make them blind. They
eat outwards from the eyes. Why? Why did you do that to us? You could
easily have made a creation in which that didn't exist. It is simply not
acceptable.
lyttlec <lyttlec@removegmail.com>: Nov 13 12:44PM -0500

Is there a header that has the default day and month names in both
short(Mon, Tue, etc) and long (Monday, Tuesday, etc. ) forms? I'm trying
to avoid writing and using extra char arrays
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 13 12:15PM +0100

On 13.11.2016 00:00, Paavo Helde wrote:
> in to alleviate the inherent defect in the design of unsigned integers -
> discontinuity at zero. If there were no unsigned numbers, such a hack
> would not be needed.
 
Rather, the wrapping for both signed and unsigned is because it would in
general, and in particular on modern computer architectures, require
extra work to avoid it, e.g. to trap, because wrapping is the natural &
automatic result of computing with a fixed number of digits.
 
The choice of whether to treat it as UB (as for signed types in C++) or
to require it (as for unsigned types in C++) seems more arbitrary. The
UB does allow some optimizations of loops, because the compiler can
freely assume that there will no be wrapping (e.g., in `x < y+1`). But
since the wrapping is occasionally practically useful, it would be just
as reasonable, maybe more reasonable, to provide a way to explicitly
tell the compiler to assume no wrapping in a specified region of code.
 
As I recall the g++ compiler has some option to make that assumption in
general for loops, for use when one tells it to in general assume well
defined wrapping instead of UB for signed types. Which is nice. But it
only partly alleviates the problem with that compiler choosing
unpredictable rare-case speed optimization, over predictability. Since
the standard allows and to some people encourages unpredictability, I
think the choice of UB was just wrong. Today, as I see it, UB does not
give a performance edge, neither in this single case nor in general: it
just obstructs the programmer's work by adding unpredictability. :(
 
Cheers!,
 
- Alf
Gareth Owen <gwowen@gmail.com>: Nov 13 11:28AM


> The choice of whether to treat it as UB (as for signed types in C++)
> or to require it (as for unsigned types in C++) seems more
> arbitrary
 
On of the uses for unsigned was clearly as bit-arrays for bit-twiddling
and shifting. Having an "overflowing" left-shift be UB would make them
considerably less useful.
 
Defining wrapping for unsigned arithmetic them seems to follow naturally
to be consistent with that.
"Öö Tiib" <ootiib@hot.ee>: Nov 13 07:32AM -0800

On Sunday, 13 November 2016 13:18:36 UTC+2, Alf P. Steinbach wrote:
> think the choice of UB was just wrong. Today, as I see it, UB does not
> give a performance edge, neither in this single case nor in general: it
> just obstructs the programmer's work by adding unpredictability. :(
 
So they made about 25% additions and 95% of multiplications of two signed
integers as undefined behavior and implementing in well-formed C or C++ what
the actual multiplication and addition instructions of all platforms do as
close to impossibly complex task. Why? Who needs that?
 
May be it is sabotage of large companies that propose their proprietary
languages to replace C and C++. They see it beneficial that here are
C#, Swift, Go and Java but no C nor C++.
Paavo Helde <myfirstname@osa.pri.ee>: Nov 13 05:32PM +0200

On 13.11.2016 13:28, Gareth Owen wrote:
 
> On of the uses for unsigned was clearly as bit-arrays for bit-twiddling
> and shifting. Having an "overflowing" left-shift be UB would make them
> considerably less useful.
 
Sure, there are data types which are useful for bit twiddling and in OS
kernel structures and of course they have strong hardware support. But
IMO these should have been called "bit registers" or something, not
"unsigned integers". An "unsigned integer" type looks for me more like
some kind of special data structure like std::complex.
 
Cheers
Paavo
woodbrian77@gmail.com: Nov 12 05:09PM -0800

On Saturday, November 12, 2016 at 9:18:22 AM UTC-6, Tim Rentsch wrote:
> guidelines, or heuristics, for how to discover a good design,
> but they are means to an end, not an end in itself. As with
> geometry, there is no royal road to making good design choices.
 
 
There's "A Royal Road to Algebraic Geometry" by Holme, Audun.
http://www.springer.com/us/book/9783642192241
 
 
Perhaps the royal road is doing the right thing given the context.
 
 
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
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: