“xor eax, ebp” being used in C++ compiler output

These are buffer overrun protection methods, and have nothing to do with compiler optimisation. MSVC will (if you specify the /GS switch) push a security cookie onto the stack near the return address so that it can detect a common case of stack corruption. Stack corruption can either be caused by bad code along the … Read more

Can different optimization levels lead to functionally different code?

The portion of the C++ standard that applies is ยง1.9 “Program execution”. It reads, in part: conforming implementations are required to emulate (only) the observable behavior of the abstract machine as explained below. … A conforming implementation executing a well-formed program shall produce the same observable behavior as one of the possible execution sequences of … Read more

Does the C# compiler treat a lambda expression as a public or private method?

It depends. With the current version of Visual Studio, the methods that implement lambdas are never public, but they’re not always private. A simple program to test some versions of lambdas: public class Program { public static void Main() { var program = new Program(); Try(“A”, program.A); Try(“B”, program.B); Try(“C”, program.C); Console.ReadKey(); } private static … Read more

Why doesn’t a compiler optimize floating-point *2 into an exponent increment?

For example, 2 * f, might simply increment the exponent of f by 1, saving some cycles. This simply isn’t true. First you have too many corner cases such as zero, infinity, Nan, and denormals. Then you have the performance issue. The misunderstanding is that incrementing the exponent is not faster than doing a multiplication. … Read more

Unexpected result when C++ store element into std::vector from return value of function

The behaviour is undefined in all C++ versions before C++17. The simple reason is that the two sides of the assignment operator can be evaluated in any order: Assuming A[1] is evaluated first, you get an int& referring to the second element of A at that point. Then, the func() is evaluated, which can reallocate … Read more

Is this a compiler optimisation bug, or an undefined behaviour?

This is a code optimizer bug. It inlines both getData() and SetBit(). The combination appears to be fatal, it loses track of the value of 1 << ((pos) & 7) and always produces zero. This bug does not occur on VS2012. A workaround is to force one of the functions to not get inlined. Given … Read more

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