- size_t - 3 Updates
- Why won't this compile... - 1 Update
- New vector class with range checking - 1 Update
- 'class' and 'struct' at link time - 3 Updates
- decimal - 4 Updates
- [Webinar] Accelerating DevOps & Continuous Integration - 1 Update
- Could you explain a copy member function to me? - 1 Update
- extern declare in a template - 3 Updates
- Could you explain a copy member function to me? - 3 Updates
- Want to readout the control file of aria2. - 3 Updates
- Help on 'delete[] data' in an example - 1 Update
- Could you explain std::multiset in the class definition to me? - 1 Update
legalize+jeeves@mail.xmission.com (Richard): Jun 08 10:50PM [Please do not mail me a copy of your followup] slp53@pacbell.net spake the secret code > for (ssize_t i = str.size()-1; i >= 0; i--) { > std::cout << str[i]; > } Did you mean size_t instead of ssize_t? Because size_t is unsigned, this is an infinite loop. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
David Brown <david.brown@hesbynett.no>: Jun 09 08:21AM +0200 On 09/06/15 00:50, Richard wrote: >> } > Did you mean size_t instead of ssize_t? > Because size_t is unsigned, this is an infinite loop. ssize_t is a signed version of size_t. It is not part of the C standards, but is (I think) in posix. |
scott@slp53.sl.home (Scott Lurndal): Jun 09 01:53PM >> } >Did you mean size_t instead of ssize_t? >Because size_t is unsigned, this is an infinite loop. I meant "ssize_t" of course, since it is a signed type. |
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 09 09:25AM -0400 On 6/8/2015 5:21 PM, Doug Mika wrote: > template <typename C> > vector<typename C> create_container(int size){ > return vector<typename C> myVector(size); I do not believe this is correct syntax, but I am not your compiler. > cout<<"The size is: "<<(create_container<string>(3)).size()<<endl; > return 0; > } ...and the error message is ...? See FAQ 5.8. V -- I do not respond to top-posted replies, please don't ask |
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 09 09:24AM -0400 On 6/8/2015 3:55 PM, Doug Mika wrote: > Vec<int> myVector; > this will call: > vector<int> myVector? Yes, *as part of constructing* your Vec<int>. > Vec<string> myVector(3,"default"); > this will call > vector<string> myVector(3, "default"); Most likely. > upon the creation of a Vec instance, then I should re-write all > vector<T>::vector constructors in Vec and call these explicitly from > my defined Vec<T> constructors? Yes. Inheriting constructors is only useful if your data members require only default-initialization or your class has no additional members. V -- I do not respond to top-posted replies, please don't ask |
gwowen <gwowen@gmail.com>: Jun 09 03:13AM -0700 Just hit the following in VS2013 // x.hpp class Xpimpl; class X { Xpimpl *p; public: X(int a_); void frob(); }; // x.cpp #include "x.hpp" struct Xpimpl { int a; }; X::X(int a_) : p(new Xpimpl) { p->a = a_; } void X::frob() { ++p->a; } /// main.cpp int main(void) { X x(7); x.frob(); } This compiles and runs with g++ / Ubuntu but give a linker error in VS2013. The reason seems to be that Xpimpl is forward declared as a "class" but actually declared as a struct. Change the forward declaration to struct Xpimpl; and everything works. So ... compiler bug, or UB due to subtle mismatch in declaration and definition. |
Mel <mel@zzzzz.com>: Jun 09 01:28PM +0300 On Tue, 9 Jun 2015 03:13:33 -0700 (PDT), gwowen <gwowen@gmail.com> wrote: > x.frob(); > } > This compiles and runs with g++ / Ubuntu but give a linker error in VS2013. > The reason seems to be that Xpimpl is forward declared as a "class" but actually declared as a struct. Change the forward declaration to > struct Xpimpl; > and everything works. So ... compiler bug, or UB due to subtle mismatch in declaration and definition. I guess that compiler is allowed to mangle class or struct as well. But this is not logical as one can't define both class and struct with same name. -- Press any key to continue or any other to quit |
"Öö Tiib" <ootiib@hot.ee>: Jun 09 04:32AM -0700 On Tuesday, 9 June 2015 13:13:52 UTC+3, gwowen wrote: > The reason seems to be that Xpimpl is forward declared as a "class" but actually declared as a struct. Change the forward declaration to > struct Xpimpl; > and everything works. So ... compiler bug, or UB due to subtle mismatch in declaration and definition. It looks like a compiler bug. The 'struct' and 'class' mean same thing in context of forward declaration. I am not sure why such inconsistent usage is permitted but AFAIK it must compile and run. |
Robert Wessel <robertwessel2@yahoo.com>: Jun 08 05:24PM -0500 On 8 Jun 2015 20:39:46 GMT, jt@toerring.de (Jens Thoms Toerring) wrote: >than 20 Million Dollar/Euro) a long integer will do quire >nicely. Or go for a int64 if you've got to deal with the >worlds combined GNPs;-) The problem is not so much the actual values (where 64-bit ints will adequately deal with almost any amount of currency you might encounter), rather the intermediate results. Consider multiplying a large number of pennies by a percentage expressed as five decimal digits (.01..999.99%). If you're working with 32 bit ints, that will overflow at about $214. 64-bit ints go a little farther, but you still overflow with something as simple as multiplying $10M by a couple of percentages (assuming you aren't, as is true in some cases, allowed to round between the two multiplications), or some $922B for a single percentage (which is barely adequate to handle Exxon's annual revenue, to say nothing of, say, Mexico's GDP), so a fair bit of care is still required. A 128-bit intermediate type goes a long way to making currency calculations straight-forward. |
Christopher Pisz <nospam@notanaddress.com>: Jun 08 05:41PM -0500 On 6/8/2015 3:39 PM, Jens Thoms Toerring wrote: > you have only a finite amount of bits to store such a number > in. So there's no simple solution to the "I want two decimal > digits" problem. I thought that was what the boost multiprecision library took care of. It was to use base 10. But see below, my demo code doesn't make sense to me. I understand what 0.1f ends up looking like in binary, but I don't understand how to get around the problem. > actually need and write your code to do exactly what you want > it to do. So what's the exact scenario where rounding won't > do? Well, rounding will probably do in most scenarios I can think of, even though I'd have to round to a different decimal place depending what I am dealing with. Money - 2 digits, Time clock punches - maybe 4, performance timer - 8... something like that. I was really hoping there was just some C++ equivalent to the decimal type they have in other languages. I read the other's posts about existance of libraries. I thought the boost multiprecision was one such library. > ments call for an infinite amount of memory for storing just a > single number;-) > Regards, Jens I tried the following demo code and the output makes no sense to me: #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/math/special_functions/gamma.hpp> #include <iostream> int main() { typedef boost::multiprecision::cpp_dec_float_50 Decimal; Decimal numberBoost = 2.13f; float numberFloat = 2.13f; double numberDouble = 2.13; std::string numberAsText("2.13"); std::cout << "The float number is: " << std::fixed << std::setprecision(12) << numberFloat << std::endl; std::cout << "The double number is: " << std::fixed << std::setprecision(12) << numberDouble << std::endl; std::cout << "The boost number is: " << std::fixed << std::setprecision(12) << numberBoost << std::endl; std::istringstream converter(numberAsText); converter >> numberDouble; std::cout << "The number converted from string and back is " << numberDouble << std::endl; return 0; } Output: The float number is: 2.130000114441 The double number is: 2.130000000000 The boost number is: 2.130000114441 The number converted from string and back is 2.130000000000 The double seemed to print to console as the original number, while I expected it wouldn't. The debugger say's it is holding 2.12999999 The boost number did not print to console matching the original number. The float printed with a error in positive contrary to what the debugger told me about the double, which had error in the negative. I read over the link Victor posted, but I am honestly pretty lost now. I thought I understood what was going on, but evidently I don't. -- I have chosen to troll filter/ignore all subthreads containing the words: "Rick C. Hodgins", "Flibble", and "Islam" So, I won't be able to see or respond to any such messages --- |
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Jun 09 12:46AM -0600 On Mon, 08 Jun 2015 17:41:53 -0500, Christopher Pisz <nospam@notanaddress.com> wrote: <snip> > Decimal numberBoost = 2.13f; > float numberFloat = 2.13f; > double numberDouble = 2.13; <snip> >The boost number did not print to console matching the original number. >The float printed with a error in positive contrary to what the debugger >told me about the double, which had error in the negative. My guess is that at least part of your problem is with "2.13f". The "f" tells the compiler to store the constant as single-precision floating point, which means that you lose whatever added precision you might have had if you'd said "2.13d" or if you'd simply said "2.13", as you did when you initialized numberDouble. Remember that the compiler doesn't know and doesn't care that you're going to be using the constant to initialize something of type double or of type numberBoost. (What happens if you initialize numberDouble with 2.13f?) Keep in mind, too, that some Intel CPUs use 80-bit floating point registers, and you *might* be getting more precision than you expected. This has been a source of confusion for years; if a value is written to memory as a 64-bit double-precision floating point value and is then read from memory, you get one thing, and if it's used straight from an 80-bit register, you get something slightly different. Louis |
"Öö Tiib" <ootiib@hot.ee>: Jun 09 04:21AM -0700 On Tuesday, 9 June 2015 01:42:07 UTC+3, Christopher Pisz wrote: > The double seemed to print to console as the original number, while I > expected it wouldn't. The debugger say's it is holding 2.12999999 > The boost number did not print to console matching the original number. Your "original number" was C++ float constant value '2.13f'. 2.13f is *impossible* to represent as IEEE 754 float exactly so compiler has to take 2.13000011444091796875f that happens to be closest to 2.13 that float *can* represent. So that value *is* in your boost number. Precision of 50 decimal places does not help if you fill it with garbage. > The float printed with a error in positive contrary to what the debugger > told me about the double, which had error in the negative. You initialized the values with different constants ('2.13f' and '2.13'). If you use same constant for double then you get same output with it as well: #include <iostream> #include <iomanip> int main() { double numberDouble = 2.13f; std::cout << "The double number is: " << std::fixed << std::setprecision(25) << numberDouble << std::endl; return 0; } Output: The double number is: 2.1300001144409179687500000 Note that this outcome is not regulated by C++ standard but by IEEE Standard for Floating-Point Arithmetic (IEEE 754). C++ standard keeps being rather quiet about floating point arithmetic. > I read over the link Victor posted, but I am honestly pretty lost now. > I thought I understood what was going on, but evidently I don't. The paper is discussing exactly the issue that you have above and several other issues that you will very likely face soon enough. It might take more than few hours to read and to understand the paper. |
Avi Hein <avi@incredibuild.com>: Jun 09 02:26AM -0700 Please register for DevOps and Continuous Delivery on Steroids on Jun 24, 2015 10:00 AM EDT at: https://attendee.gotowebinar.com/register/8416505691059815425?source=complangcpp Team members use Agile and Continuous Delivery methodologies to increase efficiency, enabling frequent releases, while improving software quality. Breaking down silos between development groups and the development/operations divide accelerates delivery. Testing, release, staging, and deployment are streamlined and force agility and increased efficiency. Build automation helps accelerate build processes by automating many of the tasks that developers, QA, build managers, and anyone else involved in the build process do in their day-to-day activities. This is where speed is becoming essential. Learn how to make your continuous integration run on steroids. Discover: * Continuous Integration automation challenges & benefits * How to identify build flow bottlenecks * How to lower continuous integration cycles times * How multicore and distributed computing can accelerate your continuous integration * The effect of faster build cycles on a single developer, team, and the entire development organization When: June 24, 2015 at 10:00 AM EDT, 3:00 PM GMT, 7:30 PM IST (India) The webinar will be recorded, so if you can not attend live, sign up and you will receive the recording after the event. (Note: all code examples will be in C++ and with C++ builds) |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 09 05:55AM >>class Wilma { }; >Given the code you have shown, yes. The declaration of Wilma on line >1 is a "forward declaration" whose only purpose is to allow p_ to be ... >Before you code can compile, someone must complete the declaration for >Wilma. Otherwise, any expression of the form "new Wilma" will >generate a diagnostic that the size of Wilma is not known. #include <iostream> #include <ostream> class alpha {}; int main(){ ::std::cout << sizeof alpha {} << '\n'; } prints »1« here. sizeof alpha {} is know! |
Joe <no.spam@noemail.com>: Jun 08 09:27PM -0500 I've got a header that extern declares a var which is defined within a globals.cpp. I do this for very few globals. --- globals.h #pragma once extern MyGlobalClass my_gclass; --- globals.cpp MyGlobalClass my_gclass; --- aclass.h #include "globals.h" template <class SomeClass> class AnotherClass { // ... void operator()() { my_gclass->func(...); } }; The problem is that it won't compile. aclass.h:102:29: error: 'my_gclass' was not declared in this scope error = my_gclass->func(... I don't understand that since the #include "globals.h" is in aclass.h. However, if I add "extern MyGlobalClass my_gclass;" just after #include "globals.h in the aclass.h template file, it works. Can someone explain this? |
Paavo Helde <myfirstname@osa.pri.ee>: Jun 08 11:50PM -0500 > However, if I add "extern MyGlobalClass my_gclass;" just after #include > "globals.h in the aclass.h template file, it works. > Can someone explain this? Probably some confusion with namespaces. Or a spelling mistake, recheck your names for silly errors like license/licence. hth Paavo |
Barry Schwarz <schwarzb@dqel.com>: Jun 08 10:48PM -0700 >However, if I add "extern MyGlobalClass my_gclass;" just after #include >"globals.h in the aclass.h template file, it works. >Can someone explain this? Instead of compiling a .h file, create a .cpp file which includes aclass.h (along with Somme trivial function definition) and see if that works. -- Remove del for email |
fl <rxjwg98@gmail.com>: Jun 08 04:54PM -0700 Hi, I am still new to C++. When I read a post on-line, I do not understand one line: Fred(const Fred& f) : p_(new Wilma(*f.p_)) { } ---------------------- class Wilma { }; class Fred { public: Fred() : p_(new Wilma()) { } Fred(const Fred& f) : p_(new Wilma(*f.p_)) { } ~Fred() { delete p_; } private: Wilma* p_; }; ----------------------- I know that f is a reference to a Fred object. *f.p_ is the pointer of object f. My question is about Wilma(*f.p_) or new Wilma(*f.p_) is class Wilma incomplete? Please explain it to me if you can. Thanks, |
Paavo Helde <myfirstname@osa.pri.ee>: Jun 08 11:43PM -0500 fl <rxjwg98@gmail.com> wrote in > Fred(const Fred& f) : p_(new Wilma(*f.p_)) { } > ---------------------- > class Wilma { }; Wilma is complete, it has the full definition {}; > Wilma(*f.p_) > or > new Wilma(*f.p_) This allocates and constructs a new Wilma object, based on an old one. The copy constructor of Wilma is used. As Wilma does not define a copy constructor, the compiler generates one by default. > is class Wilma incomplete? No. hth Paavo |
Barry Schwarz <schwarzb@dqel.com>: Jun 08 10:36PM -0700 >}; >----------------------- >I know that f is a reference to a Fred object. *f.p_ is the pointer of object f. My question is about Not quite. p_ is a private member of the class Fred. It has type pointer to Wilma. f is a reference to a particular instance of the class Fred. f.p_ is the pointer that is the member of that particular instance. *f.p_ is the actual Wilma object that f.p_ points to. >or >new Wilma(*f.p_) >is class Wilma incomplete? Given the code you have shown, yes. The declaration of Wilma on line 1 is a "forward declaration" whose only purpose is to allow p_ to be defined. Since p_ is a pointer to a class, the compiler does not need to know any of the internal specifics of that class before defining a pointer to it. (All pointers to any class have the same size, representation, and alignment requirements.) Before you code can compile, someone must complete the declaration for Wilma. Otherwise, any expression of the form "new Wilma" will generate a diagnostic that the size of Wilma is not known. >Please explain it to me if you can. The copy constructor will only be called when you "execute" code similar to: Fred x; Fred y(x); When x is defined, the specified *default* constructor, Fred(), executes. This constructor allocates space for a Wilma and stores the address in x.p_. Whether the allocated space is initialized or retains whatever residual data happened to be in memory depends on Wilma's default constructor. When y is defined, the specified *copy* constructor, Fred(const Fred& f), executes. This also allocates space for a Wilma but specifies the current value of *x.p_ (that is , the contents of the class Wilma object that x.p_ points to) should be used to initialize the newly created Wilma. The net result is that x.p_ and y.p_ each point to a separate object of type Wilma but both objects contain the same data. (In a perverse design, the Wilma default and copy constructors could cause the contents to differ.) -- Remove del for email |
Hongyi Zhao <hongyi.zhao@gmail.com>: Jun 08 11:20PM Hi all, I want to read out the control file of aria2, which is a binary file including the data format depicted here: http://aria2.sourceforge.net/manual/en/html/technical-notes.html Could you please give me some snipped codes for this purpose? I've attached a file for you information. Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. |
Hongyi Zhao <hongyi.zhao@gmail.com>: Jun 08 11:20PM =ybegin line=128 size=123 name=boot.img.gz.aria2 *+*********:******,HaH***********/!)© ª***.***.*:*****2)ê*********:*:*****2)))))) ****D*:*****2)ª*********K*8aH***2))))=J*** =yend size=123 crc32=4e08d58b |
Barry Schwarz <schwarzb@dqel.com>: Jun 08 10:02PM -0700 On Mon, 8 Jun 2015 23:20:20 +0000 (UTC), Hongyi Zhao >http://aria2.sourceforge.net/manual/en/html/technical-notes.html >Could you please give me some snipped codes for this purpose? >I've attached a file for you information. Make up your mind. Do you want to do it in C as your post in comp.lang.c suggests or in C++ as your post here suggests? Please remember that while the two languages have enough features in common they are separate. -- Remove del for email |
Paavo Helde <myfirstname@osa.pri.ee>: Jun 09 12:00AM -0500 fl <rxjwg98@gmail.com> wrote in > When I read a post on-line about self-assignment, I do not understand > one line: > delete[] data; Everything allocated by new[] ("data = new int[n];" in your example) must be deleted by delete[]. Beware that in real life the array-style new[] and delete[] have about zero usage cases. These come up almost only in silly learning examples like this. > n? > Whether they are meant to an array length n, beginning address is by a > pointer data? It seems so. A poor-man reimplementation of std::vector, I guess. hth Paavo |
legalize+jeeves@mail.xmission.com (Richard): Jun 08 10:47PM [Please do not mail me a copy of your followup] fl <rxjwg98@gmail.com> spake the secret code >In a general for loop, the third is the step size for the variable. Maybe you have C++ confused with BASIC-PLUS's for loop:[1] FOR I = 1 TO N STEP 3 In a general for C++ loop, the third chunk is the *iteration expression*. <http://en.cppreference.com/w/cpp/language/for> It is an expression that advances the iteration. When using integral type loop variables or iterator loop variables, the expression ++i or --i is most common and this iteration expression updates the underlying loop variable because ++i is the same as i = i + 1 for an integral type loop variable. We could just as easily write something like: for (int i = 0; i < 10; i = fn(i)) { } without any difficulty. [1] See page 3-16 <http://bitsavers.trailing-edge.com/pdf/dec/pdp11/rsts/V06/DEC-11-ORBPB-A-D_BASIC-PLUS_LangMan_Jul75.pdf> -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
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:
Post a Comment