C++ Forced Cast Library
A super-duped reliable (no matter how strict you make the command line flags, it still just keeps getting compiled no matter what!) C++ library that allows willy-nilly type-casting.
Click Here To Download The Library
Code example:
#include <iostream>
#include "force_cast.hpp"
int main( void ) {
unsigned short my_Ull[2];
my_Ull[0] = 1;
my_Ull[1] = 1;
/* Will it compile?!?!?! */
std::cout << (unsigned int)force_cast<int>( my_Ull ); //Now you try doing this with those annoying little buggy standard casting functions
/* (Suprize, Suprize!) It does!, even in strict -Wall -Wextra -ansi -fno-hosted -std=c++98 -Werror -Wpedantic mode, the compile still doesnt catch this amazing little hack! */
std::cout << "\n";
return 0;
}
List below are some common questions you might have.
- How does it work? It super-duper over exploits a tiny little over-sight in the creation of the Mingw compiler to on the order of the size of the universe!
- How do I use it? It's just like the reinterpret_cast function, except that this force_cast function doesnt put up a hissy-fit when you try to do a conversion that is (supposed to be) disabled for very very very good reasons.
- What are the limitations? Just two limitations:
- When the type your converting to is bigger than the origional type, there should be a segmentation fault error (but for some odd reason I don't getting an error when I compile).
- The variable you are trying to convert to
- Performance? You might as well make your whole program dependent on this function because it realy is that fast (its only but a few clock cycles as this whole function works by only just copy-n-pasting a pointer, then indirectly getting the object it pointes to)