|
Thug Bonnet posted:That is super clever, but it's not my struct In that case, you're stuck setting the members of the struct in the body of the class constructor, barring some language feature I'm unaware of.
|
# ? Jul 31, 2008 09:38 |
|
|
# ? Jun 8, 2024 17:48 |
|
prolecat posted:In that case, you're stuck setting the members of the struct in the body of the class constructor, barring some language feature I'm unaware of. Since structs have a default copy constructor, you can define a function that returns said struct (something like MyStruct MakeDefaultMyStruct()) and initialize the member variable with that.
|
# ? Jul 31, 2008 10:20 |
|
StickGuy posted:Are there any software packages out there that can analyze C/C++ floating point calculations to identify sensitive ones or suggest different orders of operations? Ideally something that could check based on the actual values used in the calculations. The standard for linear algebra is LAPACK, Matlab is actually build on top of it. GSL (GNU Scientific Library: http://www.gnu.org/software/gsl/) is a good wrapper, since the original Fortran -> C interface can be quite daunting at first, especially with function names like DGESV. *EDIT* Quoted the wrong post, this is an answer for Chin Strap. Groceries Stealer fucked around with this message at 19:17 on Jul 31, 2008 |
# ? Jul 31, 2008 13:09 |
|
prolecat posted:In that case, you're stuck setting the members of the struct in the body of the class constructor, barring some language feature I'm unaware of. code:
|
# ? Jul 31, 2008 13:21 |
|
FrankFerl posted:The standard for linear algebra is LAPACK, Matlab is actually build on top of it. GSL (GNU Scientific Library: http://www.gnu.org/software/gsl/) is a good wrapper, since the original Fortran -> C interface can be quite daunting at first, especially with function names like DGESV.
|
# ? Jul 31, 2008 15:21 |
|
Chin Strap posted:Figure this is a good place to ask:
|
# ? Jul 31, 2008 15:24 |
|
floWenoL posted:Since structs have a default copy constructor, you can define a function that returns said struct (something like MyStruct MakeDefaultMyStruct()) and initialize the member variable with that. Lexical Unit posted:Well he could do Yes, but in both cases, you're creating an extra temporary copy of the struct, in addition to not using initialization lists to initialize its members, correct? I'm guessing that copy would probably be optimized out, but still.
|
# ? Jul 31, 2008 16:49 |
|
prolecat posted:Yes, but in both cases, you're creating an extra temporary copy of the struct, in addition to not using initialization lists to initialize its members, correct? I'm guessing that copy would probably be optimized out, but still. But still what? Always write code that's easier to read first, and if it turns out to be slow for whatever reason, then optimize it.
|
# ? Jul 31, 2008 17:31 |
|
Avenging Dentist posted:But still what? Always write code that's easier to read first, and if it turns out to be slow for whatever reason, then optimize it. Well then putting aside the initialization list it seems like just doing assignment in the constructor would be more readable?
|
# ? Jul 31, 2008 17:46 |
|
Avenging Dentist posted:But still what? Always write code that's easier to read first, and if it turns out to be slow for whatever reason, then optimize it. I have to disagree when the optimization in question is something that's already very easy to do and just as readable (in my opinion). No sense being slow when there's really no reason.
|
# ? Jul 31, 2008 17:51 |
|
Thug Bonnet posted:Well then putting aside the initialization list it seems like just doing assignment in the constructor would be more readable? As long as you have all trivial datamembers or if you aren't that concerned with efficiency, use whichever one you find easier to read. It won't matter. prolecat posted:I have to disagree when the optimization in question is something that's already very easy to do and just as readable (in my opinion). No sense being slow when there's really no reason. If you are so concerned about optimization, all floWenoL's version needs out of a compiler is NRVO support (which most if not all modern compilers support), and in the case of a struct with non-trivial assignment, floWenoL's version will likely be more optimized whether NRVO is supported or not. Edit: In the case of all trivial datamembers, I agree, the version with assignments done in the constructor is the simplest approach and likely just as efficient. That Turkey Story fucked around with this message at 18:08 on Jul 31, 2008 |
# ? Jul 31, 2008 18:04 |
|
StickGuy posted:It's more that I already have a C++ program that performs lots of complicated floating point calculations and I want an automated way of finding and improving places where accuracy may be being lost. Sorry, I actually quoted the wrong post. I was answering this one: Chin Strap posted:Figure this is a good place to ask:
|
# ? Jul 31, 2008 19:16 |
|
is there a way to determine endianess of a floating point number at runtime in either C++ or Java? Is this something that cannot be determined from data alone? I am reading a binary file and would like to know if I have to reverse the bits or not.
|
# ? Aug 1, 2008 02:09 |
|
Entheogen posted:is there a way to determine endianess of a floating point number at runtime in either C++ or Java? Is this something that cannot be determined from data alone? I am reading a binary file and would like to know if I have to reverse the bits or not. Why wouldn't you do that at compile time?
|
# ? Aug 1, 2008 02:13 |
|
Avenging Dentist posted:Why wouldn't you do that at compile time? What do you mean? The idea is that I will have binary files as input and some of them might have IEEE floating point numbers in one endianness and another in different one. Instead of forcing user to choose which one they would like the file to be read as, I was wondering if there is an automatic way of doing this, but my suspicion is there is not because otherwise there would have to be some sort of meta-data describing the contents of file, and there is no such data, its just floating point numbas.
|
# ? Aug 1, 2008 03:36 |
|
Avenging Dentist posted:Why wouldn't you do that at compile time? Because you might be reading from a source with the endian-ness swapped. Entheogen posted:is there a way to determine endianess of a floating point number at runtime in either C++ or Java? Is this something that cannot be determined from data alone? I am reading a binary file and would like to know if I have to reverse the bits or not. Software I worked on knows if endian-ness is swapped by checking known fields. Example, the month as a 32-bit integer. It should never be 0, and will not be greater than 12. If you read it as 213134142 or something, swapped endian-ness. This will only work if you can find a piece of data like this. We just fixed a bug where the date was set to 0/0/0 and it broke the endian swap code, so this is fragile. However, it is better than nothing. IEEE floating point also has values that should never exist (I think). You could search for these and that could tell you to swap. :edit: If you can guarantee no NaN or Inf values in the data, looking for NaN or Inf values could also be a hint. litghost fucked around with this message at 03:42 on Aug 1, 2008 |
# ? Aug 1, 2008 03:38 |
|
litghost posted:Because you might be reading from a source with the endian-ness swapped. That's stupid. Edit for content: Seriously, what kind of rear end in a top hat would make a binary file specification without defining the endianness? Avenging Dentist fucked around with this message at 04:27 on Aug 1, 2008 |
# ? Aug 1, 2008 04:24 |
|
litghost posted:Software I worked on knows if endian-ness is swapped by checking known fields. Example, the month as a 32-bit integer. It should never be 0, and will not be greater than 12. If you read it as 213134142 or something, swapped endian-ness. This will only work if you can find a piece of data like this. We just fixed a bug where the date was set to 0/0/0 and it broke the endian swap code, so this is fragile. However, it is better than nothing. Why not just include a flag in the binary data that defines endianness? edit: maybe I should refresh before posting
|
# ? Aug 1, 2008 04:29 |
|
Or just serialize to text if you have the choice.
|
# ? Aug 1, 2008 04:33 |
|
Avenging Dentist posted:That's stupid. The reason most software is retarded, backwards compatibility. Hey I didn't write the thing, don't blame me. :edit: Did I mention it was written in FORTRAN? Lots of GOTOs. litghost fucked around with this message at 04:37 on Aug 1, 2008 |
# ? Aug 1, 2008 04:34 |
|
Avenging Dentist posted:That's stupid. I am reading in files made from Fortran where it is reverse. But I would also like my software to work with files generated with normal endianness. Ideally I don't want to rely on any sort of meta-data in the file itself to be able to successfully read it in and visualize it. I think I will try NaN and Infinite values perhaps or try to look for those bits that can never be true if its correct endianess. In worst case scenario I will just let the end-user decide what endianess they want before they read in the file.
|
# ? Aug 1, 2008 05:04 |
|
Entheogen posted:I am reading in files made from Fortran where it is reverse. But I would also like my software to work with files generated with normal endianness. Ideally I don't want to rely on any sort of meta-data in the file itself to be able to successfully read it in and visualize it. I think I will try NaN and Infinite values perhaps or try to look for those bits that can never be true if its correct endianess. In worst case scenario I will just let the end-user decide what endianess they want before they read in the file. NaN and Inf are valid values if the software allows or expects it.
|
# ? Aug 1, 2008 05:18 |
|
Entheogen posted:I am reading in files made from Fortran where it is reverse. But I would also like my software to work with files generated with normal endianness. Ideally I don't want to rely on any sort of meta-data in the file itself to be able to successfully read it in and visualize it. I think I will try NaN and Infinite values perhaps or try to look for those bits that can never be true if its correct endianess. In worst case scenario I will just let the end-user decide what endianess they want before they read in the file. What's wrong with a byte-order flag? I mean, that's how any sane person resolves this issue (see also: UTF-16). If it's a really big deal, just make the reader default to Fortran-endianness and have an optional byte-order flag.
|
# ? Aug 1, 2008 05:24 |
|
Entheogen posted:... normal endianness. No such thing. quote:I think I will try NaN and Infinite values perhaps or try to look for those bits that can never be true if its correct endianess. In worst case scenario I will just let the end-user decide what endianess they want before they read in the file. So you want to use implicit metadata and not explicit metadata. Enthogen posted:Ideally I don't want to rely on any sort of meta-data in the file itself to be able to successfully read it in and visualize it.
|
# ? Aug 1, 2008 10:42 |
|
I've decided that The Apache C++ Standard Library Reference Guide is a great web reference and easier to use than SGI's. It covers the whole standard library (while SGI's covers only containers and iterators) and they make it more obvious when something is an extension. Descriptions are formatted nicely, too. SGI's still has a place for its definitions of concepts, though.
|
# ? Aug 1, 2008 15:21 |
|
In C++, is there a standard way (in code) to stop compilation and display a custom message? I know in MSVC you can use #pragma error, but I can't rely on this for other compilers.
|
# ? Aug 2, 2008 14:11 |
|
What phase of compilation? During preprocessing you can use #error.
|
# ? Aug 2, 2008 15:05 |
|
Mustach posted:What phase of compilation? During preprocessing you can use #error.
|
# ? Aug 2, 2008 15:46 |
|
ultra-inquisitor posted:Wonderful, thanks. Probably not what you need, but in case anyone else is wondering, you can also use Boost.StaticAssert to do this at compile time (if preprocessor time is too soon/not expressive enough).
|
# ? Aug 2, 2008 20:14 |
|
That reminds me, why is it Boost convention to talk about the libraries using C# style? E.g. "Boost.StaticAssert" instead of "boost::static_assert".
|
# ? Aug 2, 2008 22:29 |
|
Perhaps to make it clear you are talking about the project and not the namespace/class/function [template]. vvvv <> Vanadium fucked around with this message at 23:32 on Aug 2, 2008 |
# ? Aug 2, 2008 22:38 |
|
Also stuff like Boost.SmartPointer isn't a namespace. They're all in the boost namespace.
|
# ? Aug 2, 2008 22:52 |
|
Mustach posted:That reminds me, why is it Boost convention to talk about the libraries using C# style? E.g. "Boost.StaticAssert" instead of "boost::static_assert". I don't know the reasoning behind it, but the Boost.Camel style is how you refer to the libraries. The actual identifiers are referred to in their C++ names, like boost::shared_ptr.
|
# ? Aug 4, 2008 16:07 |
|
Hey all, This has probably been covered, but I'm looking to generate random numbers in a Gaussian distribution. Through Google I've discovered the boost libraries, and I know they have a method for doing it. Unfortunately I'm not a professional programmer, so it's a little obtuse if I can't see an example. Basically my input would be a mean, a sigma, and potentially an integer value for the number of randomly generator numbers I want outputted. Can anyone post an example?
|
# ? Aug 4, 2008 23:20 |
|
This shows you how to do pretty much everything with Boost.Random: http://www.boost.org/doc/libs/1_35_0/libs/random/random_demo.cpp
|
# ? Aug 4, 2008 23:40 |
|
I've whipped a Gaussian random variate generator in C++ that generates numbers via a rejection technique and thrown in an implementation of the Mersenne Twister random number generator for fun. It has no dependencies aside from the standard math library http://av8r.ca/~max/gaussian.cpp The only thing to be aware of is that you need to call twister_initialize() before calling gaussian() otherwise you won't get any valid numbers.
|
# ? Aug 5, 2008 06:07 |
|
Thanks gents. I appreciate the help.
|
# ? Aug 5, 2008 17:52 |
|
Quick question, I'm trying to help a friend create a fuction that accepts a char[] as an input and outputs a char[]. How would I be able to do this? char[] myFunct(char[] myArray) normally I would use strings, but my friend wants to do it with only char[] so that it works with the rest of his code.
|
# ? Aug 7, 2008 02:34 |
|
actually, I am now doing that with pointers: char* time_incr(char* time); but how do I actually access individual chars in a char*, it just seems to spit out the offset until the null terminator each time..
|
# ? Aug 7, 2008 02:45 |
|
|
# ? Jun 8, 2024 17:48 |
|
FearIt posted:actually, I am now doing that with pointers: You can treat a pointer as an array, ex. code:
|
# ? Aug 7, 2008 03:02 |