comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* A Brief Introduction to Islam - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/a31b8ce9ae713c37?hl=en
* Can't think of a good subject - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/ff410bf5e81204c2?hl=en
* Address one past the end of array - is this syntax a valid C++? - 1 messages,
1 author
http://groups.google.com/group/comp.lang.c++/t/3660f2b84a4f1cb3?hl=en
* SMITHSONIAN SHUT DOWN FOR GOOD -- THE THRINAXODON TIMES REPORTS, YOU CALL
OUT BULLSHIT - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/91d9902b0f7df726?hl=en
* Flummoxed - Please Help! - 12 messages, 7 authors
http://groups.google.com/group/comp.lang.c++/t/d4b5a6ac1e14e414?hl=en
* IO problem - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/1627ad3e27ed2570?hl=en
* about gets - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0335e4afbf8afe82?hl=en
* pointer to a vector - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/b17f744707f37fdb?hl=en
* could an braced-init-list be a first-class expression? - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/4790566113c6b180?hl=en
==============================================================================
TOPIC: A Brief Introduction to Islam
http://groups.google.com/group/comp.lang.c++/t/a31b8ce9ae713c37?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Feb 17 2014 11:05 am
From: bv4bv4bv4@gmail.com
A Brief Introduction to Islam
A brief introduction to the meaning of Islam, the notion of God in Islam, and His basic message to humanity through the Prophets.
http://www.islamhouse.com/426146/en/en/articles/A_Brief_Introduction_to_Islam
Thank you
== 2 of 2 ==
Date: Mon, Feb 17 2014 1:26 pm
From: woodbrian77@gmail.com
On Monday, February 17, 2014 1:05:11 PM UTC-6, bv4b...@gmail.com wrote:
> A Brief Introduction to Islam
>
> A brief introduction to the meaning of Islam, the notion of God in Islam, and His basic message to humanity through the Prophets.
>
> http://www.islamhouse.com/426146/en/en/articles/A_Brief_Introduction_to_Islam
>
Franklin Graham pointed out after Sept. 11, 2001 that
it wasn't Lutherans or Methodists who hijacked those
airplanes.
I'm not aware of C++ software with Isalmic roots.
C++ Middleware Writer has Judeo/Christian roots.
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
==============================================================================
TOPIC: Can't think of a good subject
http://groups.google.com/group/comp.lang.c++/t/ff410bf5e81204c2?hl=en
==============================================================================
== 1 of 3 ==
Date: Mon, Feb 17 2014 1:11 pm
From: woodbrian77@gmail.com
On Monday, February 17, 2014 9:21:03 AM UTC-6, Chris Vine wrote:
>
> It is parsed as a variable declaration - namely the declaration of an
> object of type Test named 'b' (and also as an object definition by
> allocating stack storage for 'b'): or put another way, 'Test(b);' is
> parsed as 'Test b;'. 'b' is constructed using the default constructor
> of Test (not the type conversion constructor).
>
> It is not that unreasonable a thing to do in this case. It would
> usually be pointless to construct a temporary object which is dispensed
> with unused at the end of the statement constructing it, so you are
> unlikely to come across it. It is one of the examples in §6.8/2 of the
> C++11 standard. Presumably in this case the program author was coding
> for a side effect in a rather obfuscated way. Caveat obfuscator.
>
Constructors may have side effects. In this case
it was a File class and the ctor opens a file and
writes to it.
Perhaps your argument is more with the language
itself.
Here's the modified function:
template <class R>
void Receive (::cmw::ReceiveBuffer<R>& buf
,empty_container<cmw::File>& az1)
{
int32_t count[1];
for(count[0]=buf.template Give<uint32_t>();count[0]>0;--count[0]){
cmw::File{buf};
}
}
The loop in the original version had
cmw::File inst(buf);
The variable name, inst, was superfluous in my opinion.
Brian
Ebenezer Enterprises - So far G-d has helped us.
http://webEbenezer
== 2 of 3 ==
Date: Mon, Feb 17 2014 2:38 pm
From: Chris Vine
On Mon, 17 Feb 2014 13:11:55 -0800 (PST)
woodbrian77@gmail.com wrote:
> On Monday, February 17, 2014 9:21:03 AM UTC-6, Chris Vine wrote:
> >
> > It is parsed as a variable declaration - namely the declaration of
> > an object of type Test named 'b' (and also as an object definition
> > by allocating stack storage for 'b'): or put another way,
> > 'Test(b);' is parsed as 'Test b;'. 'b' is constructed using the
> > default constructor of Test (not the type conversion constructor).
> >
> > It is not that unreasonable a thing to do in this case. It would
> > usually be pointless to construct a temporary object which is
> > dispensed with unused at the end of the statement constructing it,
> > so you are unlikely to come across it. It is one of the examples
> > in §6.8/2 of the C++11 standard. Presumably in this case the
> > program author was coding for a side effect in a rather obfuscated
> > way. Caveat obfuscator.
> >
>
> Constructors may have side effects. In this case
> it was a File class and the ctor opens a file and
> writes to it.
>
> Perhaps your argument is more with the language
> itself.
Not really. Yours is an obfuscated way of doing it, in my view. It
would be better to have a separate object method which does the writing.
However, I don't have a problem with C++ enabling you to write
obfuscated code, if that is what you want to do.
Chris
== 3 of 3 ==
Date: Mon, Feb 17 2014 7:42 pm
From: Öö Tiib
On Monday, 17 February 2014 23:11:55 UTC+2, woodb...@gmail.com wrote:
> On Monday, February 17, 2014 9:21:03 AM UTC-6, Chris Vine wrote:
> >
> > It is parsed as a variable declaration - namely the declaration of an
> > object of type Test named 'b' (and also as an object definition by
> > allocating stack storage for 'b'): or put another way, 'Test(b);' is
> > parsed as 'Test b;'. 'b' is constructed using the default constructor
> > of Test (not the type conversion constructor).
> >
> > It is not that unreasonable a thing to do in this case. It would
> > usually be pointless to construct a temporary object which is dispensed
> > with unused at the end of the statement constructing it, so you are
> > unlikely to come across it. It is one of the examples in §6.8/2 of the
> > C++11 standard. Presumably in this case the program author was coding
> > for a side effect in a rather obfuscated way. Caveat obfuscator.
>
> Constructors may have side effects. In this case
> it was a File class and the ctor opens a file and
> writes to it.
Constructor that does rather complex operations (opens and writes to files)
has to be built to fail. Constructor can signal failures only by throwing,
with globals or having object with error state. You use temporary in loop
so that removes error state and globals and leaves throwing. On your case
it seems needless complexity.
> Perhaps your argument is more with the language
> itself.
Huh? There are *functions* in C++.
> Here's the modified function:
>
> template <class R>
> void Receive (::cmw::ReceiveBuffer<R>& buf
> ,empty_container<cmw::File>& az1)
> {
> int32_t count[1];
> for(count[0]=buf.template Give<uint32_t>();count[0]>0;--count[0]){
> cmw::File{buf};
> }
> }
Not too readable what it does. Array of ints with size 1 used instead of
single int. Why? If it fails with one file in loop how it is handled?
Rest are reverted? Failed files are retried? How the whole thing resumes
after failure here?
> The loop in the original version had
>
> cmw::File inst(buf);
>
> The variable name, inst, was superfluous in my opinion.
Having array of size 1 was fine and (possibly one-letter) name was
too much to type? With or without that 'inst' it looks cryptic
(constructor is used as function) and naive (errors likely badly
handled) code, don't you see? Why it is not typical:
result = cmw::OpenAndWriteToFile(buf);
// ... handle result
==============================================================================
TOPIC: Address one past the end of array - is this syntax a valid C++?
http://groups.google.com/group/comp.lang.c++/t/3660f2b84a4f1cb3?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Feb 17 2014 3:30 pm
From: woodbrian77@gmail.com
On Friday, February 14, 2014 10:12:50 AM UTC-6, Victor Bazarov wrote:
>
> I can't give you the exact source, unfortunately, and I am sorry. All I
> can remember is that it was mentioned here, discussed in some thread,
This might be it:
https://groups.google.com/forum/#!searchin/comp.lang.c$2B$2B/null$20reference$20victor|sort:date/comp.lang.c++/NtyXDAepnxw/-eL5DDzoO-8J
==============================================================================
TOPIC: SMITHSONIAN SHUT DOWN FOR GOOD -- THE THRINAXODON TIMES REPORTS, YOU
CALL OUT BULLSHIT
http://groups.google.com/group/comp.lang.c++/t/91d9902b0f7df726?hl=en
==============================================================================
== 1 of 2 ==
Date: Tues, Feb 18 2014 11:05 am
From: Apidium23
==============
>BREAKING NEWS
==============
>
SMITHSONIAN FINALLY SHUT DOWN AFTER YEARS OF CENSORSHIP, SCAMS AND CON
ARTISTRY.
>
THRINAXODON BLEW DOWN THE BUILDINGS, LIT IT ON FIRE AND HAD THE ASSHOLES
ARRESTED.
>
R. DAWKINS WAS THROWN IN THE DOGHOUSE, ONLY TO GET KILLED BY ANGRY
FELONS WHO WANTED PAYBACK FOR FRAMING THEM.
>
THRINAXODON DANCED ON DAWKINS' GRAVE, AND BURNED A FEW SMITHSONIAN
MAGAZINES.
>
=================================
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:
https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f#
https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82#
====================================
http://thrinaxodon.wordpress.com/
===================================
THRINAXODON ONLY HAD THIS TO SAY:
"I..I...I...Can't believe it. This completely disproved Darwinian
orthodoxy."
===================================
THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING
WITH FEAR.
===========================
THESE ASSHOLES ARE GOING TO DIE:
THOMAS AQUINAS;
ALDOUS HUXLEY;
BOB CASANVOVA;
SkyEyes;
DAVID IAIN GRIEG;
MARK ISAAK;
JOHN HARSHAM;
RICHARD NORMAN;
DR. DOOLITTLE;
CHARLES DARWIN;
MARK HORTON;
ERIK SIMPSON;
HYPATIAB7;
PAUL J. GANS;
JILLERY;
WIKI TRIK;
THRINAXODON;
PETER NYIKOS;
RON OKIMOTO;
JOHN S. WILKINS
===========================
THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A
HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT
THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD
TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY
FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep
people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS
SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That
is a myth, for people to believe in science." THRINAXODON PLANS TO
BRING DOOM TO SCIENCE, ITSELF.
============================
THRINAXODON IS NOW ON TWITTER.
======================================
>
THRINAXODON WAS AWARDED
US$100,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
DOLLARS FOR HIS BRAVE EFFORTS IN SHUTTING DOWN THE EVOLUTIONARY SCAMS.
--
Apidium23:
http://apidium23.wordpress.com/about/
== 2 of 2 ==
Date: Tues, Feb 18 2014 2:27 pm
From: "THE COLONEL"
Stuff it up yer kazoo.
==============================================================================
TOPIC: Flummoxed - Please Help!
http://groups.google.com/group/comp.lang.c++/t/d4b5a6ac1e14e414?hl=en
==============================================================================
== 1 of 12 ==
Date: Tues, Feb 18 2014 11:40 am
From: mrc2323@cox.net (Mike Copeland)
I have the following (rather simple, I think) code which compiles but
executes in a bizarre way: the code in the subprogram is skipped when
called. 8<{{
Here's the code and the call to it I use:
string spellNumber(double value)
{
bool showThousands = false;
bool allZeros = true;
int ii, dPos, nn;
char wc;
string digits, temp;
ostringstream ossw;
static string builder;
ossw.str("");
ossw << value;
digits = ossw.str();
dPos = digits.find('.');
if(dPos != string::npos) digits.erase(dPos);
nn = digits.length();
wc = digits.back();
for(ii = digits.length()-1; ii >= 0; ii--)
{
int ndigit = (int)(digits[ii]-'0');
int column = (digits.length()-(ii+1));
} // for
// more code to be added here
return builder;
}
...
spellNumber(123.45); // call the function
I have, of course the normal stdafx.h header and "use namespace
std;", and this is code from a small test program I use to debug new
functions and such. Many other programs and many thousands of lines of
code work fine, but this code is weird...and I can't see what's wrong
with it!
Please advise... TIA
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
== 2 of 12 ==
Date: Tues, Feb 18 2014 12:13 pm
From: Victor Bazarov
On 2/18/2014 2:40 PM, Mike Copeland wrote:
> I have the following (rather simple, I think) code which compiles but
> executes in a bizarre way: the code in the subprogram is skipped when
> called. 8<{{
> Here's the code and the call to it I use:
>
> string spellNumber(double value)
> {
> bool showThousands = false;
> bool allZeros = true;
> int ii, dPos, nn;
> char wc;
> string digits, temp;
> ostringstream ossw;
> static string builder;
> ossw.str("");
> ossw << value;
> digits = ossw.str();
> dPos = digits.find('.');
> if(dPos != string::npos) digits.erase(dPos);
> nn = digits.length();
> wc = digits.back();
> for(ii = digits.length()-1; ii >= 0; ii--)
> {
> int ndigit = (int)(digits[ii]-'0');
> int column = (digits.length()-(ii+1));
> } // for
> // more code to be added here
> return builder;
> }
> ...
> spellNumber(123.45); // call the function
>
> I have, of course the normal stdafx.h header and "use namespace
> std;", and this is code from a small test program I use to debug new
> functions and such. Many other programs and many thousands of lines of
> code work fine, but this code is weird...and I can't see what's wrong
> with it!
> Please advise... TIA
The logic error is on the line 42 of your original program, at least
according to my crystal ball, which is the best source of information I
have at this point, since you've chosen not to post the entire program.
http://www.parashift.com/c++-faq/posting-code.html
V
--
I do not respond to top-posted replies, please don't ask
== 3 of 12 ==
Date: Tues, Feb 18 2014 1:06 pm
From: mrc2323@cox.net (Mike Copeland)
In article <le0eu5$gnl$1@dont-email.me>, v.bazarov@comcast.invalid
says...
> > I have the following (rather simple, I think) code which compiles but
> > executes in a bizarre way: the code in the subprogram is skipped when
> > called. 8<{{
> > Here's the code and the call to it I use:
> > Please advise... TIA
>
> The logic error is on the line 42 of your original program, at least
> according to my crystal ball, which is the best source of information I
> have at this point, since you've chosen not to post the entire program.
>
> http://www.parashift.com/c++-faq/posting-code.html
Fair enough; I was sloppy. Here's the entire program code:
// CPP10 Test Bed Program MRCopeland 02/18/2014
#include "stdafx.h"
string spellNumber(double value)
{
int ii, dPos, nn;
char wc;
string digits;
ostringstream ossw;
static string builder;
ossw.str(""); // Convert integer portion of value to string
ossw << value;
digits = ossw.str();
dPos = digits.find('.');
if(dPos != string::npos) digits.erase(dPos);
nn = digits.length(); // Traverse characters in reverse order
wc = digits.back();
for(ii = digits.length()-1; ii >= 0; ii--)
{
int ndigit = (int)(digits[ii]-'0');
int column = (digits.length()-(ii+1));
} // for
return builder;
}
int main(int argc, char *argv[])
{
string str = spellNumber(123.45);
return EXIT_SUCCESS;
} // main
During execution, the following occurs during the IDE trace:
1. The subprogram is entered and immediately jumps to the "return
builder" statement. (Why?)
2. Then, the function is reentered and code steps are taken - until the
"if" statement executes. The logic works as expected with the data
presented ("digits" is runcated to "123"), whereupon the function exits
(!).
3. The statements beyond the "if" are skipped for no apparent reason.
Any thoughts?
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
== 4 of 12 ==
Date: Tues, Feb 18 2014 1:34 pm
From: Paavo Helde
mrc2323@cox.net (Mike Copeland) wrote in
news:MPG.2d6d79599d6e9e40989763@news.eternal-september.org:
>
> During execution, the following occurs during the IDE trace:
> 1. The subprogram is entered and immediately jumps to the "return
> builder" statement. (Why?)
> 2. Then, the function is reentered and code steps are taken - until
> the
> "if" statement executes. The logic works as expected with the data
> presented ("digits" is runcated to "123"), whereupon the function
> exits (!).
> 3. The statements beyond the "if" are skipped for no apparent reason.
> Any thoughts?
Apparently you are trying to debug a Release (aka optimized) build program
in the Visual Studio. Optimized compilation may have optimized away half of
your lines and is otherwise confusing the IDE. In short, do not attempt to
do that, if you want to debug, use a Debug (non-optimized) build!
hth
Paavo
== 5 of 12 ==
Date: Tues, Feb 18 2014 1:40 pm
From: Victor Bazarov
On 2/18/2014 4:06 PM, Mike Copeland wrote:
> In article <le0eu5$gnl$1@dont-email.me>, v.bazarov@comcast.invalid
> says...
>>> I have the following (rather simple, I think) code which compiles but
>>> executes in a bizarre way: the code in the subprogram is skipped when
>>> called. 8<{{
>>> Here's the code and the call to it I use:
>>> Please advise... TIA
>>
>> The logic error is on the line 42 of your original program, at least
>> according to my crystal ball, which is the best source of information I
>> have at this point, since you've chosen not to post the entire program.
>>
>> http://www.parashift.com/c++-faq/posting-code.html
>
> Fair enough; I was sloppy. Here's the entire program code:
> // CPP10 Test Bed Program MRCopeland 02/18/2014
> #include "stdafx.h"
> string spellNumber(double value)
> {
> int ii, dPos, nn;
> char wc;
> string digits;
> ostringstream ossw;
> static string builder;
> ossw.str(""); // Convert integer portion of value to string
> ossw << value;
> digits = ossw.str();
> dPos = digits.find('.');
> if(dPos != string::npos) digits.erase(dPos);
> nn = digits.length(); // Traverse characters in reverse order
> wc = digits.back();
> for(ii = digits.length()-1; ii >= 0; ii--)
> {
> int ndigit = (int)(digits[ii]-'0');
> int column = (digits.length()-(ii+1));
> } // for
> return builder;
> }
> int main(int argc, char *argv[])
> {
> string str = spellNumber(123.45);
> return EXIT_SUCCESS;
> } // main
>
> During execution, the following occurs during the IDE trace:
> 1. The subprogram is entered and immediately jumps to the "return
> builder" statement. (Why?)
> 2. Then, the function is reentered and code steps are taken - until the
> "if" statement executes. The logic works as expected with the data
> presented ("digits" is runcated to "123"), whereupon the function exits
> (!).
> 3. The statements beyond the "if" are skipped for no apparent reason.
> Any thoughts?
I took your code and made only one change:
//#include "stdafx.h"
#include <string>
#include <sstream>
using std::string;
using std::ostringstream;
(since I have no idea what was in your 'stdafx.h' header). The program
compiled and ran fine (under the debugger). Stepping through it showed
that it followed all statements and returned an empty string (since no
change is made to 'builder' object in the 'spellNumber' function).
It sounds that you're trying to debug an optimized version of your
program (a "release" version). Perhaps you should disable optimizations
in order to step through it. The optimizer is often not the best tool
for verifying the logic of your program because it can determine and
throw away the code that has no effect. For instance, all the code that
follows the 'if' statement has no side effect (no change is made to any
memory location that would be noticed by the caller of the function),
methinks.
V
--
I do not respond to top-posted replies, please don't ask
== 6 of 12 ==
Date: Tues, Feb 18 2014 5:06 pm
From: mrc2323@cox.net (Mike Copeland)
> > During execution, the following occurs during the IDE trace:
> > 1. The subprogram is entered and immediately jumps to the "return
> > builder" statement. (Why?)
> > 2. Then, the function is reentered and code steps are taken - until the
> > "if" statement executes. The logic works as expected with the data
It gets weirder and weirder...
First, I'm not producing (or testing) a Release version, and I have
no non-normal optimizations set. I'm running "vanilla" VS2010 Express,
afaics.
Second, there are other things going that I hadn't mentioned:
1. As I debug, some of the variables in the function don't show up, nor
can I see their values during execution by holding my mouse over them
while the code is being stepped through. (Highly unusual!.) The
variables that don't show are all the scalars (ints and chars), while
the non-scalars do show (and change as code executes).
2. I have tried moving the position of the scalar variables within the
routine, but no change there.
3. I moved the scalars outside of the routine (making them global
<gasp!>), and they show and change, as execution proceeds - as they
should.
4. Also, once these scalars are moved and debug normally, the code runs
through the logic provided (!). (I know that nothing really changes in
terms of the return string, but there's more logic to be added to do
some of that - I'm just working out the logic to handle the data and
expand it as needed.)
Thus, it appears that the problem of code that isn't executed within
the routine is some effect of the scalar data declared and used in the
code (totally odd, in my experience...). I'm at a complete loss to
understand this... 8<{{
Here's my latest code (which as I said is working as I step through
the debugger). <sigh>
#include <string>
#include <sstream>
using std::string;
using std::ostringstream;
int ii, dPos, nn;
char wc;
int ndigit;
int column;
string spellNumber(double value)
{
string digitStr;
ostringstream ossw;
static string builder;
ossw.str(""); // Convert integer portion of value to string
ossw << value, digitStr = ossw.str();
dPos = digitStr.find(".");
if(dPos != string::npos)
digitStr.erase(dPos);
nn = digitStr.length(); // Traverse characters in reverse order
wc = digitStr.back();
for(ii = digitStr.length()-1; ii >= 0; ii--)
{
ndigit = (int)(digitStr.at(ii)-'0');
column = (digitStr.length()-(ii+1));
} // for
// more logic to be added here...
return builder;
}
int main(int argc, char *argv[])
{
string str = spellNumber(123.45);
return EXIT_SUCCESS;
} // main
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
== 7 of 12 ==
Date: Tues, Feb 18 2014 5:27 pm
From: Ed Anson
On 2/18/14 8:06 PM, Mike Copeland wrote:
>>> During execution, the following occurs during the IDE trace:
>>> 1. The subprogram is entered and immediately jumps to the "return
>>> builder" statement. (Why?)
>>> 2. Then, the function is reentered and code steps are taken - until the
>>> "if" statement executes. The logic works as expected with the data
>
> It gets weirder and weirder...
> First, I'm not producing (or testing) a Release version, and I have
> no non-normal optimizations set. I'm running "vanilla" VS2010 Express,
> afaics.
> Second, there are other things going that I hadn't mentioned:
> 1. As I debug, some of the variables in the function don't show up, nor
> can I see their values during execution by holding my mouse over them
> while the code is being stepped through. (Highly unusual!.) The
> variables that don't show are all the scalars (ints and chars), while
> the non-scalars do show (and change as code executes).
> 2. I have tried moving the position of the scalar variables within the
> routine, but no change there.
> 3. I moved the scalars outside of the routine (making them global
> <gasp!>), and they show and change, as execution proceeds - as they
> should.
> 4. Also, once these scalars are moved and debug normally, the code runs
> through the logic provided (!). (I know that nothing really changes in
> terms of the return string, but there's more logic to be added to do
> some of that - I'm just working out the logic to handle the data and
> expand it as needed.)
> Thus, it appears that the problem of code that isn't executed within
> the routine is some effect of the scalar data declared and used in the
> code (totally odd, in my experience...). I'm at a complete loss to
> understand this... 8<{{
> Here's my latest code (which as I said is working as I step through
> the debugger). <sigh>
> #include <string>
> #include <sstream>
> using std::string;
> using std::ostringstream;
> int ii, dPos, nn;
> char wc;
> int ndigit;
> int column;
> string spellNumber(double value)
> {
> string digitStr;
> ostringstream ossw;
> static string builder;
> ossw.str(""); // Convert integer portion of value to string
> ossw << value, digitStr = ossw.str();
> dPos = digitStr.find(".");
> if(dPos != string::npos)
> digitStr.erase(dPos);
> nn = digitStr.length(); // Traverse characters in reverse order
> wc = digitStr.back();
> for(ii = digitStr.length()-1; ii >= 0; ii--)
> {
> ndigit = (int)(digitStr.at(ii)-'0');
> column = (digitStr.length()-(ii+1));
> } // for
> // more logic to be added here...
> return builder;
> }
>
> int main(int argc, char *argv[])
> {
> string str = spellNumber(123.45);
> return EXIT_SUCCESS;
> } // main
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
Your new observations are just more proof that what others surmised must
be true: You are debugging an optimized version. What you are seeing is
precisely what an optimizer will do to your code.
== 8 of 12 ==
Date: Tues, Feb 18 2014 5:36 pm
From: Öö Tiib
On Wednesday, 19 February 2014 03:06:52 UTC+2, Mike Copeland wrote:
> First, I'm not producing (or testing) a Release version, and I have
> no non-normal optimizations set. I'm running "vanilla" VS2010 Express,
> afaics.
What you describe confirm what others said. Cut that "no non-normal" crap.
Remove every last of "normal" optimizations if you want to step thru and
see things. The compiler writers of Microsoft are far wiser than debugger
writers of Microsoft that are far wiser than IDE writers of Microsoft.
So if you want to see things of your program in IDE you *must* make
the compiler as dumb as you only can.
== 9 of 12 ==
Date: Tues, Feb 18 2014 6:07 pm
From: Geoff
On Tue, 18 Feb 2014 14:06:58 -0700, mrc2323@cox.net (Mike Copeland)
wrote:
>In article <le0eu5$gnl$1@dont-email.me>, v.bazarov@comcast.invalid
>says...
>> > I have the following (rather simple, I think) code which compiles but
>> > executes in a bizarre way: the code in the subprogram is skipped when
>> > called. 8<{{
>> > Here's the code and the call to it I use:
>> > Please advise... TIA
>>
>> The logic error is on the line 42 of your original program, at least
>> according to my crystal ball, which is the best source of information I
>> have at this point, since you've chosen not to post the entire program.
>>
>> http://www.parashift.com/c++-faq/posting-code.html
>
> Fair enough; I was sloppy. Here's the entire program code:
>// CPP10 Test Bed Program MRCopeland 02/18/2014
>#include "stdafx.h"
>string spellNumber(double value)
>{
> int ii, dPos, nn;
> char wc;
> string digits;
> ostringstream ossw;
> static string builder;
> ossw.str(""); // Convert integer portion of value to string
> ossw << value;
> digits = ossw.str();
> dPos = digits.find('.');
> if(dPos != string::npos) digits.erase(dPos);
> nn = digits.length(); // Traverse characters in reverse order
> wc = digits.back();
> for(ii = digits.length()-1; ii >= 0; ii--)
> {
> int ndigit = (int)(digits[ii]-'0');
> int column = (digits.length()-(ii+1));
> } // for
> return builder;
>}
>int main(int argc, char *argv[])
>{
> string str = spellNumber(123.45);
> return EXIT_SUCCESS;
>} // main
>
> During execution, the following occurs during the IDE trace:
> 1. The subprogram is entered and immediately jumps to the "return
>builder" statement. (Why?)
> 2. Then, the function is reentered and code steps are taken - until the
>"if" statement executes. The logic works as expected with the data
>presented ("digits" is runcated to "123"), whereupon the function exits
>(!).
> 3. The statements beyond the "if" are skipped for no apparent reason.
> Any thoughts?
The code as posted (and after making changes to make it compile due to
missing definitions) copies nothing into builder, the returned string
is empty.
== 10 of 12 ==
Date: Tues, Feb 18 2014 6:16 pm
From: Geoff
On Tue, 18 Feb 2014 18:06:52 -0700, mrc2323@cox.net (Mike Copeland)
wrote:
>> > During execution, the following occurs during the IDE trace:
>> > 1. The subprogram is entered and immediately jumps to the "return
>> > builder" statement. (Why?)
>> > 2. Then, the function is reentered and code steps are taken - until the
>> > "if" statement executes. The logic works as expected with the data
>
> It gets weirder and weirder...
> First, I'm not producing (or testing) a Release version, and I have
>no non-normal optimizations set. I'm running "vanilla" VS2010 Express,
>afaics.
> Second, there are other things going that I hadn't mentioned:
> 1. As I debug, some of the variables in the function don't show up, nor
>can I see their values during execution by holding my mouse over them
>while the code is being stepped through. (Highly unusual!.) The
>variables that don't show are all the scalars (ints and chars), while
>the non-scalars do show (and change as code executes).
Are you looking at the Autos window or the Locals window? This
behavior is normal for Autos. The variables disappear as they go out
of scope.
> 2. I have tried moving the position of the scalar variables within the
>routine, but no change there.
> 3. I moved the scalars outside of the routine (making them global
><gasp!>), and they show and change, as execution proceeds - as they
>should.
You are looking at Autos window.
> 4. Also, once these scalars are moved and debug normally, the code runs
>through the logic provided (!). (I know that nothing really changes in
>terms of the return string, but there's more logic to be added to do
>some of that - I'm just working out the logic to handle the data and
>expand it as needed.)
> Thus, it appears that the problem of code that isn't executed within
>the routine is some effect of the scalar data declared and used in the
>code (totally odd, in my experience...). I'm at a complete loss to
>understand this... 8<{{
> Here's my latest code (which as I said is working as I step through
>the debugger). <sigh>
>#include <string>
>#include <sstream>
>using std::string;
>using std::ostringstream;
> int ii, dPos, nn;
> char wc;
> int ndigit;
> int column;
>string spellNumber(double value)
>{
> string digitStr;
> ostringstream ossw;
> static string builder;
> ossw.str(""); // Convert integer portion of value to string
> ossw << value, digitStr = ossw.str();
> dPos = digitStr.find(".");
> if(dPos != string::npos)
> digitStr.erase(dPos);
> nn = digitStr.length(); // Traverse characters in reverse order
> wc = digitStr.back();
> for(ii = digitStr.length()-1; ii >= 0; ii--)
> {
> ndigit = (int)(digitStr.at(ii)-'0');
> column = (digitStr.length()-(ii+1));
> } // for
>// more logic to be added here...
> return builder;
>}
>
>int main(int argc, char *argv[])
>{
> string str = spellNumber(123.45);
> return EXIT_SUCCESS;
>} // main
>
All of this returns a blank string under debug and release builds. Do
you mean to return digits, not builder?
== 11 of 12 ==
Date: Tues, Feb 18 2014 6:28 pm
From: Geoff
On Tue, 18 Feb 2014 12:40:26 -0700, mrc2323@cox.net (Mike Copeland)
wrote:
> I have the following (rather simple, I think) code which compiles but
>executes in a bizarre way: the code in the subprogram is skipped when
>called. 8<{{
> Here's the code and the call to it I use:
>
What is this function supposed to do?
>string spellNumber(double value)
>{
> bool showThousands = false;
> bool allZeros = true;
> int ii, dPos, nn;
> char wc;
> string digits, temp;
> ostringstream ossw;
> static string builder;
> ossw.str("");
> ossw << value;
> digits = ossw.str();
> dPos = digits.find('.');
> if(dPos != string::npos) digits.erase(dPos);
Line above erases the decimal point and all after. Your string is now
"123". Why do you need to do anything else to this string?
> nn = digits.length();
> wc = digits.back();
OK, nn is 3, wc is '3'. Now what?
> for(ii = digits.length()-1; ii >= 0; ii--)
> {
> int ndigit = (int)(digits[ii]-'0');
> int column = (digits.length()-(ii+1));
> } // for
WTF was this done for? You could have easily just said ndigit = nn. I
don't know what you are going to do with the column variable but they
both go out of scope when the for loop is completed, ii is 0xffffffff
(-1?) which suggests something went wrong in the loop.
>// more code to be added here
> return builder;
>}
>...
> spellNumber(123.45); // call the function
>
> I have, of course the normal stdafx.h header and "use namespace
>std;", and this is code from a small test program I use to debug new
>functions and such. Many other programs and many thousands of lines of
>code work fine, but this code is weird...and I can't see what's wrong
>with it!
== 12 of 12 ==
Date: Wed, Feb 19 2014 6:46 am
From: scott@slp53.sl.home (Scott Lurndal)
mrc2323@cox.net (Mike Copeland) writes:
>In article <le0eu5$gnl$1@dont-email.me>, v.bazarov@comcast.invalid
>says...
>> > I have the following (rather simple, I think) code which compiles but
>> > executes in a bizarre way: the code in the subprogram is skipped when
>> > called. 8<{{
>> > Here's the code and the call to it I use:
>> > Please advise... TIA
>>
>> The logic error is on the line 42 of your original program, at least
>> according to my crystal ball, which is the best source of information I
>> have at this point, since you've chosen not to post the entire program.
>>
>> http://www.parashift.com/c++-faq/posting-code.html
>
> Fair enough; I was sloppy. Here's the entire program code:
>// CPP10 Test Bed Program MRCopeland 02/18/2014
>#include "stdafx.h"
>string spellNumber(double value)
>{
> int ii, dPos, nn;
> char wc;
> string digits;
> ostringstream ossw;
> static string builder;
> ossw.str(""); // Convert integer portion of value to string
> ossw << value;
> digits = ossw.str();
> dPos = digits.find('.');
> if(dPos != string::npos) digits.erase(dPos);
> nn = digits.length(); // Traverse characters in reverse order
> wc = digits.back();
> for(ii = digits.length()-1; ii >= 0; ii--)
> {
> int ndigit = (int)(digits[ii]-'0');
> int column = (digits.length()-(ii+1));
> } // for
> return builder;
>}
>int main(int argc, char *argv[])
>{
> string str = spellNumber(123.45);
> return EXIT_SUCCESS;
>} // main
>
> During execution, the following occurs during the IDE trace:
> 1. The subprogram is entered and immediately jumps to the "return
>builder" statement. (Why?)
Because all the intervening code is optimized out as useless.
==============================================================================
TOPIC: IO problem
http://groups.google.com/group/comp.lang.c++/t/1627ad3e27ed2570?hl=en
==============================================================================
== 1 of 3 ==
Date: Wed, Feb 19 2014 6:29 am
From: nvangogh
I have come to a question in C++ Primer (p 314 , exercise 8.1) that is
not clear to me.
"Write a function that takes and returns an istream&. The function
should read the stream until it hits end-of-file. The function should
print what it reads to the standard output. Reset the stream so that it
is valid before returning the stream."
Breaking this down, the function has to do three things:
1. Read a stream until it hits end-of-file
So the >> operator reads input from an istream object - cin.
This stream's end of file can be interrogated by
cin.eof(). This returns true if the end of file bit is set which can be
tested with a bool variable
bool on = false;
on = cin.eof();
if(on == true)
// end of file is reached, else
if(on ==false)
// keep reading cin
I don't believe that this is completely correct so can someone show me
how this code should be presented?
2. Print what is read to the standard output
I can only imagine this to be cout << ? But am lost from here
3. Reset the stream so it is valid before returning the stream
This section of the problem again defeats me.
Can anyone help with this function?
== 2 of 3 ==
Date: Wed, Feb 19 2014 6:41 am
From: Victor Bazarov
On 2/19/2014 9:29 AM, nvangogh wrote:
> I have come to a question in C++ Primer (p 314 , exercise 8.1) that is
> not clear to me.
> "Write a function that takes and returns an istream&. The function
> should read the stream until it hits end-of-file. The function should
> print what it reads to the standard output. Reset the stream so that it
> is valid before returning the stream."
>
> Breaking this down, the function has to do three things:
>
> 1. Read a stream until it hits end-of-file
> So the >> operator reads input from an istream object - cin.
> This stream's end of file can be interrogated by
> cin.eof(). This returns true if the end of file bit is set which can be
> tested with a bool variable
> bool on = false;
> on = cin.eof();
> if(on == true)
> // end of file is reached, else
> if(on ==false)
> // keep reading cin
>
> I don't believe that this is completely correct so can someone show me
> how this code should be presented?
There has to be something after the 'if' and its condition to designate
the action that shall be taken when the condition is met. So, instead
of the comments ("// end of file is reached") put something there so
that the program takes the action you want it to take. Same for the
other condition.
Usually, if you only have a "either-or" situation (like in your case,
it's either the end of file or not), then there is no need for the
second 'if', a simple 'else' ought to do. Something *like*
if (on)
...
else
...
(put the proper action instead of the ellipsis)
>
> 2. Print what is read to the standard output
> I can only imagine this to be cout << ? But am lost from here
Yes, that's pretty much what you need to do.
> 3. Reset the stream so it is valid before returning the stream
> This section of the problem again defeats me.
std::cin.clear();
resets the error condition on the 'std::cin' stream.
> Can anyone help with this function?
Part of the answer can also be found in the FAQ, section 5, question 2,
if memory serves.
V
--
I do not respond to top-posted replies, please don't ask
== 3 of 3 ==
Date: Wed, Feb 19 2014 10:09 am
From: Barry Schwarz
There are at least a couple of responses in comp.lang.c++.moderated.
Please don't multipost.
On Wed, 19 Feb 2014 14:29:18 +0000, nvangogh <nvangogh@pcexpert.net>
wrote:
>I have come to a question in C++ Primer (p 314 , exercise 8.1) that is
>not clear to me.
>"Write a function that takes and returns an istream&. The function
>should read the stream until it hits end-of-file. The function should
>print what it reads to the standard output. Reset the stream so that it
>is valid before returning the stream."
>
>Breaking this down, the function has to do three things:
>
>1. Read a stream until it hits end-of-file
>So the >> operator reads input from an istream object - cin.
>This stream's end of file can be interrogated by
>cin.eof(). This returns true if the end of file bit is set which can be
>tested with a bool variable
>bool on = false;
>on = cin.eof();
>if(on == true)
>// end of file is reached, else
>if(on ==false)
>// keep reading cin
>
>I don't believe that this is completely correct so can someone show me
>how this code should be presented?
>
>2. Print what is read to the standard output
>I can only imagine this to be cout << ? But am lost from here
>
>3. Reset the stream so it is valid before returning the stream
>This section of the problem again defeats me.
>
>Can anyone help with this function?
--
Remove del for email
==============================================================================
TOPIC: about gets
http://groups.google.com/group/comp.lang.c++/t/0335e4afbf8afe82?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Feb 19 2014 10:32 am
From: Juha Nieminen
mary8shtr@gmail.com wrote:
> hi.I am writing a program.while i define some variable but program say this variable undefined.
Lucky you.
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
==============================================================================
TOPIC: pointer to a vector
http://groups.google.com/group/comp.lang.c++/t/b17f744707f37fdb?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Feb 19 2014 10:34 am
From: Juha Nieminen
A <a@a.a> wrote:
> a) does the above *v needs to be deleted?
Did you write the 'new' keyword anywhere? If not, then why exactly do
you think you would need to write 'delete'?
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
==============================================================================
TOPIC: could an braced-init-list be a first-class expression?
http://groups.google.com/group/comp.lang.c++/t/4790566113c6b180?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Feb 19 2014 10:47 am
From: pietro.cerutti@gmail.com
I'm wondering what would prevent an initialization list from being a first-class expression of type std::initializer_list.
I understand that the current standar allows braced-init-lists to appear only when assigning to a scalar of type T or to an object of a class taking an std::initializer_list in the assignment operator.
Having
void f (std::vector<double> v);
It is currently possible to do this:
auto a {1, 2, 3}:
g (a);
but not to do this:
g ({1, 2, 3});
As I see it, all information the compiler needs is there. Is there any specific reason why this isn't possible?
Thanks,
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment