comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Boost - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/81738d66827a11c8?hl=en
* Can't think of a good subject - 6 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/ff410bf5e81204c2?hl=en
* show all subset of a set - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/708873746ae8ae59?hl=en
* This is 4 u - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/e7671013dc7133f3?hl=en
* A Brief Introduction to Islam - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/a31b8ce9ae713c37?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! - 11 messages, 6 authors
http://groups.google.com/group/comp.lang.c++/t/d4b5a6ac1e14e414?hl=en
==============================================================================
TOPIC: Boost
http://groups.google.com/group/comp.lang.c++/t/81738d66827a11c8?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Feb 16 2014 11:16 am
From: Richard Damon
On 2/15/14, 5:12 AM, Tobias Müller wrote:
> Paavo Helde <myfirstname@osa.pri.ee> wrote:
>> ÷ˆ Tiib <ootiib@hot.ee> wrote in
>> news:5499b6d8-5127-428a-96a1-44df98c1a473@googlegroups.com:
>>
>>> If the objects for 'std::shared_ptr' are allocated with
>>> 'make_shared' then I haven't observed much performance
>>> difference with intrusive ref-counting. What are the key features
>>> it lacks?
>>
>> Intrusive smartpointers have a convenient property that they can be created
>> from plain pointers (like 'this') or references. Let's say you are changing
>> some function which currently has only a pointer or reference to the
>> object, and want to call some other function which expects a smartpointer,
>> or want to store a smartpointer for later use. With intrusive smartpointers
>> this is a no-braner, otherwise it becomes a PITA to pass smartpointers
>> through all those functions which actually do not need them.
>
> But that's also a bit dangerous. If a function takes a reference as
> parameter/raw pointer I usually expect that it is not taking (any kind of)
> ownership of the object.
>
> I always wondered if it useful to have a "smart object" template like:
>
> template <typename T>
> class RC : public T
> {
> public:
> /* add perfect forwarding constructors here */
> void addRef();
> void release();
> private:
> int count;
> };
>
> theoretically it combines the the advantages of internal and external
> reference counts:
> - you can use T on the stack and RC<T> as smart object, as with external
> counts.
> - performance of internal counts.
> - safety/"ownership contract" of external count: you can only create smart
> pointers from RC<T>* not from T*.
> - You can pass by raw pointer/reference and create smart pointers on
> demand, but still have the "ownership contract"
>
> Any disadvantages?
>
> Tobi
>
One issue is that RC<Base> and RC<Derived> are not related, so if you
have a collection that takes RC<Base>, there is no way to add a
RC<Derived> to it.
There probably are use cases for this, just as there are use cases for
the standard version.
== 2 of 2 ==
Date: Mon, Feb 17 2014 5:21 am
From: Öö Tiib
On Sunday, 16 February 2014 14:46:12 UTC+2, Tobias Müller wrote:
> Öö Tiib <ootiib@hot.ee> wrote:
> > On Saturday, 15 February 2014 12:12:53 UTC+2, Tobias Müller wrote:
> >> I always wondered if it useful to have a "smart object" template like:
> >>
> >> template <typename T>
> >> class RC : public T
> >> {
> >> public:
> >> /* add perfect forwarding constructors here */
> >> void addRef();
> >> void release();
> >> private:
> >> int count;
> >> };
> >>
> >> theoretically it combines the the advantages of internal and external
> >> reference counts:
> >> - you can use T on the stack and RC<T> as smart object, as with external
> >> counts.
> >> - performance of internal counts.
> >> - safety/"ownership contract" of external count: you can only create smart
> >> pointers from RC<T>* not from T*.
> >> - You can pass by raw pointer/reference and create smart pointers on
> >> demand, but still have the "ownership contract"
> >>
> >> Any disadvantages?
> >
> > The 'boost::intrusive_ref_counter' is bit better since one can regulate
> > thread safety of access to that 'count'. Also CRTP makes it simpler,
> > no need for variadic template constructor for template (that makes
> > most readers head spin).
>
> But boost::intrusive_ref_counter is basically just a helper class for
> implementing a plain normal intrusive count.
> It has none of the advantages of the above solution.
None? It may be I do not understand the advantages. We can use 'T' on
the stack and 'shared_ptr<T>' as shared object. Performance of internal
counts is there with 'make_shared'. There is 'shared_ptr::use_count'.
Usage of raw pointers directly in code does not make sense for me. I
either use standard iterators/smart pointers/references or some self-made
things. 'boost::intrusive_ref_counter' may be useful for designs
involving copy-on-write or pimpl or both. Your 'RC<T>' may be also
useful but I can not think of example.
> My RC template works with any existing class, and with appropriate
> specialization also with primitive types. Just by using RC<SomeClass> or
> RC<int>. No need to declare a wrapper. No need to decide at design time
> whether a class should be "smart".
Usage of 'RC<int>' is more likely over-engineering than
'std::shared_ptr<int>' (where 'int' may be "handle" of something needing
special "deleter"). The question is not about "smartness". There are
objects that are never "cloned" (may be "copied") and there are objects
that are never "copied" (may be "cloned"). It needs to be clear design
time what type of object it is there and smart pointers make sense only
for the second type.
==============================================================================
TOPIC: Can't think of a good subject
http://groups.google.com/group/comp.lang.c++/t/ff410bf5e81204c2?hl=en
==============================================================================
== 1 of 6 ==
Date: Sun, Feb 16 2014 6:23 pm
From: Rick P
On 2014-02-15 11:23:29 +0000, Chris Vine said:
> On Thu, 13 Feb 2014 14:10:41 -0800 (PST)
> woodbrian77@gmail.com wrote
<snip>
> You can see the effect of "the most vexatious parse" here with this:
>
> ----------- snip ------------
>
> #include <iostream>
>
> struct Test {
> int a;
> Test (int i): a(i) {std::cout << "In conversion constructor\n";}
> Test () {std::cout << "In default constructor\n";}
> };
>
> int main () {
>
> int b = 0;
> int c = 0;
>
> {
> Test(b);
> (Test(c));
> }
> }
>
> Chris
I thought I understood the most vexing parse, but then I saw this.
Could you explain how the "Test(b);" line is parsed? I thought the
most vexing parse was due to C++ treating anything that could be a
function declaration as a function declaration, but that line seems to
be parsed as a variable declaration. Thanks.
Rick
== 2 of 6 ==
Date: Mon, Feb 17 2014 7:21 am
From: Chris Vine
On Mon, 17 Feb 2014 15:23:20 +1300
Rick P <email@domain.com> wrote:
> On 2014-02-15 11:23:29 +0000, Chris Vine said:
>
> > On Thu, 13 Feb 2014 14:10:41 -0800 (PST)
> > woodbrian77@gmail.com wrote
> <snip>
> > You can see the effect of "the most vexatious parse" here with this:
> >
> > ----------- snip ------------
> >
> > #include <iostream>
> >
> > struct Test {
> > int a;
> > Test (int i): a(i) {std::cout << "In conversion constructor\n";}
> > Test () {std::cout << "In default constructor\n";}
> > };
> >
> > int main () {
> >
> > int b = 0;
> > int c = 0;
> >
> > {
> > Test(b);
> > (Test(c));
> > }
> > }
> >
> > Chris
>
> I thought I understood the most vexing parse, but then I saw this.
> Could you explain how the "Test(b);" line is parsed? I thought the
> most vexing parse was due to C++ treating anything that could be a
> function declaration as a function declaration, but that line seems
> to be parsed as a variable declaration. Thanks.
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.
Chris
== 3 of 6 ==
Date: Mon, Feb 17 2014 10:20 am
From: Rick P
On 2014-02-17 15:21:03 +0000, Chris Vine said:
<snip>
>>
>> I thought I understood the most vexing parse, but then I saw this.
>> Could you explain how the "Test(b);" line is parsed? I thought the>
>> most vexing parse was due to C++ treating anything that could be a>
>> function declaration as a function declaration, but that line seems
>> to be parsed as a variable declaration. Thanks.
>
> 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.
>
> Chris
Thanks Chris for the explanation and the pointer to the standard.
There's always something new to learn about C++.
Rick
== 4 of 6 ==
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
== 5 of 6 ==
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
== 6 of 6 ==
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: show all subset of a set
http://groups.google.com/group/comp.lang.c++/t/708873746ae8ae59?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Feb 17 2014 5:18 am
From: "J. Clarke"
In article <subsets-20140209093308@ram.dialup.fu-berlin.de>,
ram@zedat.fu-berlin.de says...
>
> Dale Fletcher <dflach@twees.au> writes:
> >Good observation. Then there is a question of unmasking the bits.
>
> Do we need vectors assuming that 64-bit integer arithmetic
> is available? On one hand, some sets might have more than
> 64 elements. (In 1997, Harkstrøm et al. reported a set with
> more than 3000 elements!)
Are you talking about some special kind of set here? The integers
constitute a set with infinitely many elements. The reals also
constitute such a set with the integers as a proper subset (note that
{the integers that can be represented with 64-bit arithmetic} and {the
reals that can be represented with IEEE floating point} are both finite
sets but both contain considerably more than 64 elements). Then there
is the set {humans} with more than 6 billion, the set {galaxies} with
"billions and billions", and the set {stars} which has "billions and
billions" in each galaxy.
> On the other hand, printing all
> subsets from a set with more than 64 elements might take
> such a long time that it is practically unfeasible, so that
> we might not have to worry at all about implementing this.
>
> When one can print 1e9 lines per second (each line containing
> a subset specification), it might still take more than
> 200000 years to print all subsets of a set with 64 elements.
> However, during that time computers might become faster,
> so that the task could be finished earlier, when the computer
> is updated using hot hardware update capabilities while it
> executes the program.
==============================================================================
TOPIC: This is 4 u
http://groups.google.com/group/comp.lang.c++/t/e7671013dc7133f3?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Feb 17 2014 7:24 am
From: 4 u
Hi ,
I can get in to meditative deep trance and help you in getting whatever you want -good health job , money etc . My vibrations will definitely bring good and positive changes . I only offer to achieve good things and not to harm anyone . I would like to help people through my psychic abilities .
http://fiverr.com/powerprayersto
==============================================================================
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: 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 11 ==
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 11 ==
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 11 ==
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 11 ==
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 11 ==
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 11 ==
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 11 ==
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 11 ==
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 11 ==
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 11 ==
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 11 ==
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!
==============================================================================
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