Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Aug 2000
Offline Last Active Today, 05:48 AM

#5259555 Sign safer on this way ?

Posted by BitMaster on 29 October 2015 - 07:22 AM

Venturing off-ttopic, is there a reason to have three results? Often it's simpler to say that zero is positive by convention.

As someone with a mathematical background I would find that extremely vexing and force me to curse the author for at least twenty minutes. If you call it like the popular function then let it do what the popular function does. If you want something different, have the courtesy to call it differently.

#5259393 Jim. Adams's book

Posted by BitMaster on 28 October 2015 - 03:43 AM

Googling for 'WSACleanup' immediately leads to this page which says the function is defined in 'Ws2_32.lib' which you apparently do not link. Fix that, then apply the same procedure to whatever errors remain.

#5259266 Unresolved Externals problem... C++ / SDL

Posted by BitMaster on 27 October 2015 - 07:51 AM

I'm not too familiar with SDL but from what I remember SDL requires you to have an alternative SDL_main entry function. Check their documentation and example for details.

#5258636 When using C++ and including d3d11.lib, do you not use the windows registry a...

Posted by BitMaster on 23 October 2015 - 03:13 AM

You don't include a library like d3d11.lib. Include files (typically *.h) are included by the compiler, libraries are linked by the linker. Those are very different steps during the build process happening by different means for a different purpose.

I don't know what happens in D3D11CreateDevice and similar functions but I would expect them to be small stubs which query the correct interfaces from the OS via COM. To my knowledge DirectX 11 is part of the OS, so you will never run into a missing DLL though the device creation might fail if the graphics card driver present does not offer sufficient support.

#5258246 "No match for call to" error, help please

Posted by BitMaster on 21 October 2015 - 12:29 AM

[...] That's why make_shared is preferred, [...]

Did you mean to say 'make_unique'?


#5258115 Confusion with smart pointers

Posted by BitMaster on 20 October 2015 - 08:46 AM

While it is true that a moved-from type does not need to be anything but destructible, types in the standard library (including std::unique_ptr) promise more unless explicitly stated otherwise (right now I could not name a type that does). I'm just going to point over to a relevant StackOverflow topic which also quotes the relevant parts of the standard. Also note that any types you want to use with the standard library (for example inside a container like std::vector) must fulfill that promise too.

Edit: That explicitly means that you are allowed to call std::unique_ptr::get() and compare the std::unique_ptr with nullptr or other pointers.

#5258077 C# Float text format in other countries

Posted by BitMaster on 20 October 2015 - 05:40 AM

Why do you not want to output values in a format that people expect to see in different countries? That is the whole point of the regional formatting in the first place, it means numbers and dates are rendered as people are used to seeing.
As long as you use the culture setting for the machine the read/write in the different formats will be as the current regional settings are configured. 
Do your users a favour and show them values in the format they expect smile.png

As someone who sits in a place where the user-expected output is different from the C locale: functions or whole programs which think they need to stick to some locale setting they detected somewhere are highly annoying and the cause of extremely frustrating problems (up to the point of utter uselessness because floating point numbers have ',' as the decimal separator and use ',' to separate numbers).
Sure, if you need to present a number to the home-and-garden end user, you probably want a localized output. But I have found that for non-trivial programs that is in the minority compared to what else regarding textual input/output you need and in some programming languages getting clean, non-regional text in- and output can be quite a drag.

#5257945 Confusion with smart pointers

Posted by BitMaster on 19 October 2015 - 01:25 PM

Calling a member function of a null-pointer is undefined behavior. You might get an error. You might get something that looks like a working program. You might get something that looks like a working program but subtly corrupts memory leading to a crash down the road with no obvious connection to the cause.

For most compilers you can call member functions on a null-pointer provided certain requirements are met (not a virtual function, does not access any member data). It's still a horribly idea. It's still undefined behavior. It could still break the next time a new compiler version comes out or you change any compiler settings.

#5257871 Assign different functions to different structs in std::vector<>

Posted by BitMaster on 19 October 2015 - 03:26 AM

The same reason as why you needed the _1 for the bind. You create a lambda taking no parameter and assign it to something expecting an int-argument.

LayerMenu.Items[3+i].Items[0].SpecialMenuOnClick = [this](int index) { this->SelectLayer(index); };

#5257859 Adding some GUI to OpenGL

Posted by BitMaster on 19 October 2015 - 01:27 AM

In the interest of satisfying my own personal demons, the framework you are talking about is called 'Qt', not 'QT'.

#5257857 Assign different functions to different structs in std::vector<>

Posted by BitMaster on 19 October 2015 - 01:09 AM

LayerMenu.Items[3+i].Items[0].SpecialMenuOnClick = std::bind(&TTERRA_TEX_OSD::SelectLayer, this, std::placeholders::_1);
Should probably do the trick although I have not used any bind since C++11 was around. See this for more details.

#5257193 GLSL Error C1502 (Nvidia): "index must be constant expression"

Posted by BitMaster on 14 October 2015 - 05:27 AM

Are you absolutely certain that line is causing the problem and not some other line? I did a quick search and found this post on StackOverflow which seems to suggest your initial usage is okay (which is also what I would have said before checking).
From experience I would be a bit surprised to learn an AMD driver accepts something it should not according to the standard but an Nvidia driver complains. Have you tried running it through the reference compiler?

#5257190 Assign different functions to different structs in std::vector<>

Posted by BitMaster on 14 October 2015 - 04:55 AM

True, however in a lot of cases it's not immediately obvious that you will ever need more than one callback type. In these cases I would strongly recommend against the polymorphism-way in C++.

In Java for example creating a quick anonymous inner class is extremely simple. It even has access to data from its enclosing scope without any extra work.
In C++ you need to define your (possibly local) observer implementation. If you need access to any data from an enclosing scope you have to transfer it there somehow which is some extra boilerplate. You might even be in a bit of a pickle regarding lifetime management of the observer.
Especially with C++11 these kind of problems don't really exist with lambdas. But even before C++11 you could reduce the complexity a lot with, for example, Boost's function objects, bind and lambdas.

#5257041 Save FreeType bitmap to file

Posted by BitMaster on 13 October 2015 - 08:01 AM

I'm not very proficient in FreeType but from glancing at the tutorial I would say you need to call FT_Render_Glyph:

The field face−>glyph−>format describes the format used for storing the glyph image in the slot. If it is not FT_GLYPH_FORMAT_BITMAP, one can immediately convert it to a bitmap through FT_Render_Glyph.

#5256995 Migrated from VC++ 2008 Express to Visual Studio 2015: Now getting linking er...

Posted by BitMaster on 13 October 2015 - 02:04 AM

I had to change some code to work with C++11, specifically not specifying the types with make_pair, so I'm not sure if it may be that something else has changed and that's what's causing this or if some settings have just been lost with the migration or what...

This has nothing really to do with C++11. It was never a good idea to specify the types with std::make_pair, the whole point of std::make_pair has always been that you don't need to do it since template argument deduction does it for you. If you want to specify the types explicitly it would have always been a easier to just construct an explicit std::pair<First, Second>().

That said, newer MSVCs appear to be a bit quirky in this case because explicit template arguments in std::make_pair actually break it. I don't think I have ever seen that with any other compiler though.