Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 22 Jul 2001
Offline Last Active Oct 14 2014 06:30 PM

Posts I've Made

In Topic: will make help me?

03 June 2014 - 12:23 PM

In some projects, includes are required to be relative to the top of the hierarchy. This allows you to have a single include directory, typically with an absolute path, and simply include headers by their full path relative that location.




In which foo.cc would include files in a manner like:


#include <boost/thread/thread.hpp>

#include <my/awesome/graphics/buffer.hpp>

#include <my/awesome/network/buffer.hpp>


By retaining the path information in the include directive you gain location independence and the ability to distinguish between several headers with the same filename.

In Topic: [C++] Is there an easy way to mimic printf()'s behavior?

03 April 2014 - 04:27 AM

Perhaps this would work:

	char str[255];


The core problem with using a C-style printf is that you have to either guess at the length of the resulting string or use one of the "safe" sized variants of printf and attempt with larger and larger buffers until the resulting string fits.


This is more pretty_fatal_stack_smash than pretty_fatal_message_format.

In Topic: Inline assembly

15 March 2013 - 09:10 AM

If you want to do runtime x86 and x86_64 code generation properly (and yes, there's use cases for it), I would recommend using Xbyak. Nice little C++ DSL to generate machine code at runtime, complete with labels, jumping to them and all sorts of nice stuff.

In Topic: D3DXMatrixTransformation2D scale problem

15 March 2013 - 07:07 AM

Division of integers in C++ truncates towards zero, discarding any fractional component of the result. If you want a floating point result, promote one or both operands to a floating point number.


As for your observed difference, if your defines just contain the tokens 1366 and 768, there is no semantic difference in your example. Remember, a preprocessor substitution is a direct textual replacement of the macro text.


That is why for when you have more complex constants you should probably use a static const number instead, as those obey precedence and scoping rules.

In Topic: sizeof() giving strange results...

22 January 2013 - 02:29 PM

operator= is supposed to return a reference: "Vector3 &operator=(const Vector3 &rhs);"


This is just convention, nowhere does the standard mandate that an copy assignment operator shall have any particular return type, it could even return void. The only requirement is that it shall have exactly one parameter as per C++11 13.5.3/1. 13.5.3/2 has an example with an copy assignment operator returning an int by value, for example.


As Álvaro mentions, if you do not declare a copy assignment operator, one will be implicitly declared and synthesised for you that does an element-wise assignment of the members.