What’s the best C++ way to multiply unsigned integers modularly safely?

Some template metaprogramming with SFINAE, perhaps. #include <type_traits> template <typename T, typename std::enable_if<std::is_unsigned<T>::value && (sizeof(T) <= sizeof(unsigned int)) , int>::type = 0> T safe_multiply(T a, T b) { return (unsigned int)a * (unsigned int)b; } template <typename T, typename std::enable_if<std::is_unsigned<T>::value && (sizeof(T) > sizeof(unsigned int)) , int>::type = 0> T safe_multiply(T a, T b) { … Read more

Portable Compare And Swap (atomic operations) C/C++ library?

OPA (Open Portable Atomics) could be a good fit for your needs. https://trac.mcs.anl.gov/projects/openpa/ It provides a consistent C API to common atomic operations across multiple platforms under an MIT-style license. The library is small and certainly meets your size requirements. The current platform list is: GCC inline assembly for x86, x86_64, ia64, PPC 440, and … Read more

How portable is mktemp(1)?

POSIX does not seem to specify mktemp(1). It looks like most modern systems have it, but the available functionality and the semantics of the options vary between implementations (so particular invocations may not be portable): mktemp(1) from OpenBSD — mktemp(1) originated in OpenBSD 2.1 mktemp(1) from FreeBSD mktemp(1) from Mac OS X — almost always … Read more

Preventing MSYS ‘bash’ from killing processes that trap ^C

I had the exact same problem – I had written a program with a SIGINT/SIGTERM handler. That handler did clean-up work which sometimes took awhile. When I ran the program from within msys bash, ctrl-c would cause my SIGINT handler to fire, but it would not finish – the program was terminated (“from the outside”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)