Why pow(10,5) = 9,999 in C++

Due to the representation of floating point values pow(10.0, 5) could be 9999.9999999 or something like this. When you assign that to an integer that got truncated. EDIT: In case of cout << pow(10.0, 5); it looks like the output is rounded, but I don’t have any supporting document right now confirming that. EDIT 2: … Read more

Adding leading underscores to assembly symbols with GCC on Win32?

One option, though dangerous, is to convince GCC to omit the ABI-required leading underscore. -fleading-underscore This option and its counterpart, -fno-leading-underscore, forcibly change the way C symbols are represented in the object file. One use is to help link with legacy assembly code. Warning: the -fleading-underscore switch causes GCC to generate code that is not … Read more

Checking available stack size in C

The getrusage function gets you the current usage . (see man getrusage). The getrlimit in Linux would help fetching the stack size with the RLIMIT_STACK parameter. #include <sys/resource.h> int main (void) { struct rlimit limit; getrlimit (RLIMIT_STACK, &limit); printf (“\nStack Limit = %ld and %ld max\n”, limit.rlim_cur, limit.rlim_max); } Please give a look at man … Read more

mingw-w64 threads: posix vs win32

GCC comes with a compiler runtime library (libgcc) which it uses for (among other things) providing a low-level OS abstraction for multithreading related functionality in the languages it supports. The most relevant example is libstdc++’s C++11 <thread>, <mutex>, and <future>, which do not have a complete implementation when GCC is built with its internal Win32 … Read more

libstdc++-6.dll not found

If you are using MingW to compile C++ code on Windows, you may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those. Version management of libraries is a pain in Windows, so I’ve found … Read more