Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 09 Dec 1999
Offline Last Active Yesterday, 03:27 PM

#5204133 Calling static member functions on objects

Posted by SiCrane on 13 January 2015 - 10:19 PM

From what I understand, allowing . and -> access for static member functions is a backwards compatibility choice. Before static member functions were added to the language, people would use ((X*)0)->f() to access member functions that didn't reference this to simulate static member functions. When static member functions were added to the language, the -> access was kept so that function definitions could be updated without needing to update function call sites.

#5197201 "defer": is this silly / broken?

Posted by SiCrane on 09 December 2014 - 10:58 AM

The first problem that comes to mind is that you're executing arbitrary code inside a destructor. If that code throws an exception during stack unwind then your program could turn into a big puddle of goo. 

#5181390 Why using std::string when you can create it yourself...

Posted by SiCrane on 18 September 2014 - 04:34 PM

Or a single template version that does all those variations based on policy classes.

#5180339 comdat folding

Posted by SiCrane on 14 September 2014 - 05:31 PM

The structs don't necessarily need to be the same size. __thiscall functions take the object argument by pointer. However, both functions are doing the same things to the same offsets into the pointer.

#5179316 Why does std::aligned_storage work only with POD?

Posted by SiCrane on 10 September 2014 - 07:40 AM

You're misreading things. That link says std::aligned_storage<>::type is POD, it doesn't say anything about any restrictions on the type you use sizeof on to get the size. 

#5174202 list index out of Range

Posted by SiCrane on 16 August 2014 - 07:48 PM

os.path is the name of a Python module. exists is the name of a function in that module. from os.path import exists says load this python module and put an alias to the exists() function into the current scope. In other words it lets you call the exists() function with exists() rather than saying os.path.exists().

#5174177 list index out of Range

Posted by SiCrane on 16 August 2014 - 05:38 PM

You passed only one argument to your script, "Ex1.txt", so argv only has length 2. Since list indices start at 0, that means argv[2] is out of bounds.

#5170787 Python IDE

Posted by SiCrane on 31 July 2014 - 09:48 PM

At work most of us use PyCharm. Those that don't tend to use vim.

#5169798 C++ std::vector vs raw array for short arrays

Posted by SiCrane on 28 July 2014 - 10:29 AM

Why exactly can't you brace-initialize this array? That isn't a C++11 only thing.

It is when your array is a member variable and you're trying to initialize it in a constructor.

#5169611 An array with multiple data types

Posted by SiCrane on 27 July 2014 - 04:05 PM

You might want to try boost::variant.

#5167072 Win32 BOOL and bool ?

Posted by SiCrane on 15 July 2014 - 08:33 PM

I actually had to double-check that info on MSDN, I thought you were trolling. But you're not. And that frightens me to death.

When it comes to the Windows API, you don't need to make stuff up. For that matter I couldn't make some of this stuff up if I tried. Another true but unbelievable detail about BOOL: there's not just one typedef or two typedefs for boolean types in the API, but three of them (that I know about): BOOL, BOOLEAN and VARIANT_BOOL. They are respectively, 4 bytes, 1 byte and 2 bytes. VARIANT_BOOL is especially interesting because it doesn't use non-zero for true but specifically 0xffff (-1 as a short). Also BOOL and VARIANT_BOOL are signed, and BOOLEAN is unsigned. BOOLEAN is a fun one because you can do accidental integer conversions that don't mean what you think they do. bool(my_int) means true if my_int is non-zero. BOOLEAN(my_int) means take the least significant byte (in other words 256 would look like false).

#5166901 Win32 BOOL and bool ?

Posted by SiCrane on 14 July 2014 - 09:32 PM

Note that sometimes the use of BOOL in the Windows API is a lie and is not actually a boolean. For the GetMessage() function, 0 indicates WM_QUIT, non-zero indicates a non-WM_QUIT message except for -1 which means an error. 

#5165733 c++ function pointers

Posted by SiCrane on 08 July 2014 - 11:32 PM

The easiest way is to use a typedef. Ex:  typedef int (*function_type)(int). Then function_type GiveMeFunctionPointer()

#5154357 c++ class vs struct+functions

Posted by SiCrane on 17 May 2014 - 08:52 PM

Assuming the member functions are non-virtual they'll compile into essentially identical machine code as functions that accept structs as pointer or reference arguments.

#5148473 C++ std::move() vs std::memcpy()

Posted by SiCrane on 20 April 2014 - 09:22 PM

One situation where memcpy() won't work but std::move() will is when the object's constructors and destructor handle self-registration. For example, if it registers itself as part of the root set to a garbage collector by giving the garbage collector it's address. If you just copy the the memory without updating the root set for the GC, the GC will be trying to use the old memory location for its sweeps.