Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Volte
Oct 4, 2004

woosh woosh
I always make sure to disable the Microsoft language extensions in the project options (I believe it's in the 'Language' section). That should keep your code relatively clean so it can be ported away from Visual C++ fairly easily. It may take away 64-bit integers all together though since C++ doesn't have one in the standard.

Adbot
ADBOT LOVES YOU

Volte
Oct 4, 2004

woosh woosh
I'm not sure why the compiler would discriminate against strings over any other class. And if it compiles at all, it's not the compiler's fault. If it really didn't support strings in structs for some reason, it would likely toss an error.

Volte
Oct 4, 2004

woosh woosh
I'm just dicking around with boost::spirit making a parser for a sort of JSON-ish config file format (actually inspired by .irssi/config). The grammar is defined as such:
code:
definition(config_grammar const& self) {
    document            = declarations;
    declarations        = +declaration;
    declaration         = key >> "=" >> val >> ";";
    key                 = +bs::anychar_p;
    val                 = group | arr | bs::longest_d[bs::int_p | bs::real_p] | string_literal;
    group               = "{" >> declarations >> "}";
    arr                 = "{" >> arr_values >> "}";
    arr_values          = val % ",";
    string_literal      = "\"" >> *bs::anychar_p >> "\"";
}
This is supposed to represent a document with the following style:
code:
name = "John Brown";
phone-numbers = {
    "123-456-7890",
    "444-444-4444",
    "987-765-5432"
};
children = {
    {
        name = "Stephanie";
        age = 11;
        gender = "Female";
        lucky-numbers = { 9, 10, 22, 33 };
    },
    {
        name = "Slint";
        age = 21;
        gender = "Male";
        lucky-numbers = { 13, 420, 666 };
    }
};
The problem is, no matter what I put into this parser, be it the above document, a single line, or even a blank string, it enters into an infinite recursive loop and run out stack space. Anyone have any ideas what could be causing this? I'm using space_p as the skip parser if it matters.

Volte fucked around with this message at 07:33 on Jan 24, 2009

Volte
Oct 4, 2004

woosh woosh
Thanks, I fixed that as well as changing key to bs::lexeme_d[+(bs::alnum_p | bs::punct_p)]; and it works now. No idea why it doesnt stack overflow anymore... I think maybe VS was loving me over by not recompiling the parser even though I was editing the file, so some old bug stuck around no matter what changes I made. The example document clears the parser now.

Volte
Oct 4, 2004

woosh woosh

Ugg boots posted:

What do you mean spaces in attributes of tags? This isn't valid XML: <House The Name="White House" />. Unless you mean spaces in the attribute values, then that's a pretty big bug that would be missed by the TinyXML team.
A quick search revealed that it really is a big bug: http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/160005956931

Volte
Oct 4, 2004

woosh woosh
Managed C++ is a really stupid thing to use unless you're porting legacy C++ code to the .NET platform. If you are starting anew, you might as well just use C# in that case.

Volte
Oct 4, 2004

woosh woosh
Does the domain that you are testing on include numbers near the roots? It could be that the first approximation is returning denormal numbers for numbers near pi and zero and the second one is doing arithmetic on them, which would be extremely slow.

Volte
Oct 4, 2004

woosh woosh
Strangely the best free way to transparently edit remote files on Windows I've found is using Notepad++ with the bundled NppFtp plugin, which supports SFTP. I'm not a huge fan of Notepad++ in general but that particular feature is really nice, and Notepad++ is pretty lightweight.

Volte
Oct 4, 2004

woosh woosh

Pollyanna posted:

Apparently it needs 10.6.8 to run and I have no idea where to find a copy of Snow Leopard :bang: God, I miss Windows.
It works on Lion and Mountain Lion too :confused:

Volte
Oct 4, 2004

woosh woosh
Netbeans and Eclipse are probably the best C++ IDEs other than Visual Studio. Eclipse CDT has been around for at least 10 years and Netbeans has supported C++ for 4-5 years also. Personally I prefer just using a nice text editor but if you really need IDE features, there's nothing wrong with Netbeans or Eclipse.

Volte
Oct 4, 2004

woosh woosh
Taylor series are generally really bad for computing elementary functions. A better method is by finding polynomials that approximate the function (something like Mathematica can compute these) to the desired precision within some small interval (like [0, pi/8] is enough for sin) and then reducing the range of the input so that it falls into that interval, and transforming the output back to the correct value through creative use of identities.

One way to do exp (it's actually easier to calculate exp2 and then scale the input accordingly to do other bases: exp(x) = exp2(x * log2(e))) would be to construct an IEEE number directly, since the exponent is stored directly in the bit pattern. So if the input is x = p + q where p is the integer part and q is the fraction (so 0.0 <= q < 1.0), then you just need to compute exp2(p + q) = exp2(p) * exp2(q), where exp2(p) is constructed directly and and it's much easier to compute exp2(q) when the range is reduced like that. The hard part of doing functions like this is getting as close to last-bit accuracy as possible for the entire range of inputs, as well as correctly handling denormalized numbers, zero, infinity, and NaN. Those things were only hard in my experience in doing this because the focus was always on maximum performance (as in no branches at all) and strict accuracy requirements, so if you aren't too concerned about that, then it should not be very difficult at all.

Volte
Oct 4, 2004

woosh woosh
pow is pretty much always insanely expensive. pow(2,x) is completely unnecessary anyway since you can just insert the exponent directly into the bits of the floating point number. In fact any time that you are doing pow(C,x) with constant C, you can replace it with exp(x * log(C)) where log(C) is precomputed for a much cheaper evaluation. Chances are that pow is implemented with some combination of exp and log anyway, but computed in higher precision so it'll be even more expensive.

code:
float exp2(int x) {
    int a = (x + 127) << 23;
    return *(float *)&a;
}

int main() {
    // 8.000000 0.500000 32.000000
    printf("%f %f %f\n", exp2(3), exp2(-1), exp2(5));
    return 0;
}

Volte
Oct 4, 2004

woosh woosh

Combat Pretzel posted:

Forgot to mention, the exponents are floating point and can be negative.
Ah, well in that case you can still use exp(x * log(2)). The math library might even have an exp2 function in it depending on the platform.

Sorry for the undefined behaviour. For some reason I thought that setting a union's value through one member and then accessing it with a different member was equally undefined, so I did it the simpler way. My mistake. v:shobon:v

Volte
Oct 4, 2004

woosh woosh

mjau posted:

The exp2 function should be available anywhere pow/exp/etc are. C99 added float and long double versions (exp2f/exp2l)
I think exp2 was only added to the standard in C99. I would think it would be available pretty much everywhere, but it's not a guarantee.

Volte
Oct 4, 2004

woosh woosh

rjmccall posted:

If you're designing a library with binary stability requirements, sure, you have to be more circumspect. Of course, if it's a C library then type names aren't part of your binary interface, and if it's a C++ library then all of your public declarations should be namespaced. But designing the interface to a library with binary stability requirements is never something you should do casually.
Are you seriously suggesting that if cairo_t changes its name that it's reasonable to expect every single developer of a Cairo app that has ever existed to change every instance of it in their own code? If you make a change that causes ten thousand other people do have to perform emergency maintenance work then you probably made a lovely decision.

Volte
Oct 4, 2004

woosh woosh

Hughlander posted:

When interviewing people for an engineering position, I always ask them to rate themselves on a scale of 1-10 with how well they know C++. Anytime someone self-rates themselves as a 9 or 10 I ask RVO questions. I hate people who self rate at 9 or 10 and are really at like a 6 or 7.
Yeah I hate people who say they are the wrong thing on a made-up scale.

Volte
Oct 4, 2004

woosh woosh
For one thing it may implicitly alter the calling convention of the function, since the return value can't go into a register anymore.

Volte
Oct 4, 2004

woosh woosh
String literals are guaranteed to have static storage duration, so it's perfectly safe.

Volte
Oct 4, 2004

woosh woosh

tractor fanatic posted:

How do people do GUI Windows programming in C++ nowadays? Is there a favored framework, or is it a mix of MFC, ATL, QT, etc?
I've been using Qt for a project and I really like it, but you have to pretend you aren't really programming in C++ (and in some respects you aren't, since Qt has a preprocessor that extends the language slightly). You pretty much have to embrace the entire Qt ecosystem, including their STL replacement classes. I recommend against using Qt Creator for coding though, which kind of sucks. If you're using Qt4 it's really easy to get CMake set up to do the build process for you (it's supposedly even easier in Qt5 but I couldn't get it to work) so you can use an editor of your choice. For something less invasive there's wxWidgets but I've never used it extensively. Qt has everything and the kitchen sink though and it's very easily extensible. The new version of Qt has a new C++-less framework called Qt Quick which is a similar idea to WPF but is based on a Javascript derivative called QML.

Contrary to what others have said I would not recommend using WPF with .NET. WPF is a great idea but I've found its execution to be extremely bad and I hope you like writing XML. Granted I haven't used it extensively in about five years but the problems were fairly deeply rooted in the overall design. XAML is incredibly verbose, and lacks the ability to inline code (you can embed code literally but it's not useful or recommended) so you end up with a lot of indirection in your interface design, like having to define Converters and Commands all over the place to do the two most fundamental tasks in WPF, bind data and react to events. The time you save in having a declarative interface definition language might well be lost in the development overhead introduced by that language being god awful in almost every respect.

I've never used QML and don't know if it's actually good but take a look at this example (from Wikipedia) and think about how much it would take to do it in WPF:
code:
Rectangle {
    function calculateMyHeight() {
        return Math.max(otherItem.height, thirdItem.height);
    }
    anchors.centerIn: parent
    width: Math.min(otherItem.width, 10)
    height: calculateMyHeight()
    color: { if (width > 10) "blue"; else "red" }
 }

Volte
Oct 4, 2004

woosh woosh
In the context of a ray tracer, it's very useful to have Point and Vector be different classes. This lets affine transformations do the right thing automatically by cancelling the translation when transforming a Vector. You will probably also want to define a third type for Normal, since applying transformations to a normal does not affect them in the same way (see http://medialab.di.unipi.it/web/IUM/Waterloo/node45.html).

Volte
Oct 4, 2004

woosh woosh
What are you gaining by using template-level vector sizes? For 2-, 3-, and 4-vectors it makes sense since you often use them explicitly (although probably you'd be better off using separate classes, especially for matrices) but for large vectors I can't think of a scenario when you'll be explicitly using Vec<1024> rather than having your vector sizes depend on some data from a file or problem specification.

Volte
Oct 4, 2004

woosh woosh
Fair enough, although if you care about instruction-level optimization you'll probably end up specializing the member functions anyway to provide implementations for the specific small sizes.

In the large case though I can't see how having it in the template argument is at all usable. Unless all your vector sizes are known at compile time (which seems unlikely in the general case) the vector class will be useless.

Volte
Oct 4, 2004

woosh woosh
the <x.h> headers have to declare them in the global namespace, and the <cx> headers have to declare them in the std namespace, but either one might declare them in both. If you want to be able to definitely for sure use them without specifying std:: then you need to use <x.h>, but I've never heard of a compiler library that doesn't import into the global namespace in the <cx> headers. As far as not polluting the global namespace, just don't include them in a header. There's not really such a thing as "polluting" the namespace in a cpp file since it doesn't bleed into any other files.

Volte
Oct 4, 2004

woosh woosh
Typedef is just like a regular variable declaration with the word typedef in front. int variable; -> typedef int typename;

This particularly applies to function pointers.

Volte
Oct 4, 2004

woosh woosh
I'm trying to get my CMake project that uses clang and C++11 (libc++) to work with Google Test but I keep getting errors of the following sort during linking:

quote:

Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char const*, unsigned long, unsigned long) const", referenced from:
[20 pages of errors]
My guess is that it's there are conflicting standard libraries but I am building Google Test with the same flags (-stdlib=libc++ -std=c++11) as my project (verified through make VERBOSE=1), enabling GTEST_USE_OWN_TR1_TUPLE (apparently this is no longer needed on trunk), and linking them using the FindGTest module (with the GTEST_ROOT variable set on the command line) that comes with CMake 2.8. I'd rather avoid keeping gtest in my repository and building it as part of the same build process.

Volte fucked around with this message at 01:51 on May 4, 2013

Volte
Oct 4, 2004

woosh woosh

Plorkyeran posted:

Obvious reason would be if -stdlib=libc++ is only getting passed to the compiler and not to the linker.
Whoops, that was it. I was setting the wrong linker flags variable in CMake. Thanks.

Volte
Oct 4, 2004

woosh woosh

Jewel posted:

Can anyone actually tell me why functions and conditionals don't need the semicolon at the end of the brackets but classes and structs do?
Here's a C grammar: http://www.lysator.liu.se/c/ANSI-C-grammar-y.html#declaration

To answer your question, the top level constructs in a translation unit are function definitions and declarations. Function definitions don't require one but declarations could be variable declarations, function declarations, and type declarations, and no matter which one it is, it's terminated by a semicolon. A struct block is actually a type itself, so you can do
code:
struct { int a; int b; } var;
According to that grammar (and tested with GCC) you can for some reason do this:
code:
const;
int;
typedef;

Volte
Oct 4, 2004

woosh woosh

ratbert90 posted:

Erm, no? Declaring your variables should generally be done well in advance, so that way they have memory assigned to them already. If anything, your variables *should* be in a struct (or object) for code reusability. Why would you declare j over and over and over in different functions if you could just use a single variable in a object or struct that was set at initialization.

Also the code you posted only works with C99 and above, and is dependent on the compiler, it is always safer to declare your variable first, and then use it later on. :)
Please tell us where you learned this

Volte
Oct 4, 2004

woosh woosh

Ephphatha posted:

It makes it clearer that the second parameter is used as a size, not a count. Plus the whole sizeof returning a size_t thing.
The thing you quoted literally says that size_t is used for counts, so how does it make anything clearer? sizeof does not return a size_t because a size_t is not a type, it's a typedef. It's literally equivalent to whatever the underlying type is. If you replace int with size_t you are gaining nothing and losing nothing.

Volte
Oct 4, 2004

woosh woosh

Grocer Goodwill posted:

Well, you do lose quite a few bugs in your 64-bit build. But 4 gigs ought to be enough for anybody...
The int in question contains a number between 1 and 8, I don't know of any compiler whose int type is less than 4 bits.

Volte
Oct 4, 2004

woosh woosh
It's like they say: you can't build anything with LEGO until you've mastered injection moulding.

Volte
Oct 4, 2004

woosh woosh
I put that code into godbolt.org to see what exactly I'd have to do to make clang actually put a runtime typeid lookup in there, and it turns out that you have to not only change typeid(T) to typeid(butt), but you also have to make sure that there are at least two different code paths to the same function call where the compiler can't deduce the actual type of the argument. I did it by instantiating either WeakButt or StrongButt (both subclasses of virtual base class Butt) based on the result of a call to rand(). Even just doing Butt *butt = new WeakButt(); and passing in butt still allowed it to compute the typeid as being WeakButt at compile time.

Volte
Oct 4, 2004

woosh woosh
If it's affecting subsequent runs in the editor it must be doing something to the editor state that persists after the game is stopped, either clobbering it or stale data not being garbage collected properly would be my initial guesses. If there are static variables being used somewhere they shouldn't be I think that could also cause weirdness like that.

Volte
Oct 4, 2004

woosh woosh
The documentation says that there's a deprecated FString overload as well as an FText overload, so it could be that the deprecated overload is just broken.

Volte
Oct 4, 2004

woosh woosh
CMake isn't even a competitor to make so I don't really know where this discussion is coming from. I've rarely seen a project that was literally just a hand-written Makefile, nor would I ever want to write or maintain that. CMake is a competitor to something like autotools, and I'll take CMake any day.

Volte
Oct 4, 2004

woosh woosh
On Windows I generally just use the installer.

Volte
Oct 4, 2004

woosh woosh
In all my years of trying I've never found a library that could live up to Qt. GTK isn't terrible, especially in these days of Electron-everything where the old "but it doesn't look native" complaints seem downright quaint, but it doesn't have the breadth of functionality. Once you get the Qt libraries in place either through the installer, vcpkg, or even just building it from source yourself, it's really easy to get it integrated with a CMake project. No need for any of the weird qmake stuff like in the old days.

Volte
Oct 4, 2004

woosh woosh
CMake seems horrible until you understand that when you give programmers elegant tools to manage build processes with powerful abstractions and clearly defined semantics, they will use those tools to create inscrutable horrors that cause you to go mad just by looking at them.

Volte
Oct 4, 2004

woosh woosh
Unsigned int should usually mean "raw bit pattern" not "integer value that logically can't be negative". Sometimes even values that can't be negative can be subtracted from and you end up with really stupid bugs when the difference would be negative. Subtracting two vector sizes to get the difference between them? Better make drat sure to check which one's bigger first.

Adbot
ADBOT LOVES YOU

Volte
Oct 4, 2004

woosh woosh

roomforthetuna posted:

This but the exact opposite. Classes suck, smart pointers are good.
I have some bad news about smart pointers

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply