Is free() zeroing out memory?

There’s no single definitive answer to your question. Firstly, the external behavior of a freed block will depend on whether it was released to the system or stored as a free block in the internal memory pool of the process or C runtime library. In modern OSes the memory “returned to the system” will become … Read more

Clang C++ Cross Compiler – Generating Windows Executable from Mac OS X

Here are step-by-step instructions for building a Hello World .exe using llvm/clang on Mac OS X. Cross-compile Hello World for Windows using Clang/LLVM on Mac OS X Install llvm with homebrew. This will include the clang and the llvm linker. brew install llvm You’ll need access to Visual Studio C++ libraries and headers, which are … Read more

How do I make an infinite empty loop that won’t be optimized away?

The C11 standard says this, 6.8.5/6: An iteration statement whose controlling expression is not a constant expression,156) that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation … Read more

Why is processing an unsorted array the same speed as processing a sorted array with modern x86-64 clang?

Several of the answers in the question you link talk about rewriting the code to be branchless and thus avoiding any branch prediction issues. That’s what your updated compiler is doing. Specifically, clang++ 10 with -O3 vectorizes the inner loop. See the code on godbolt, lines 36-67 of the assembly. The code is a little … Read more

linking with clang++ on OS X generates lots of symbol not found errors

I suspect this issue is because of the two C++ runtime libraries available under OS X. Use the following to link the dynamic library: clang++ -stdlib=libc++ -o Analysis.dylib -shared DataFile.o CR39DataFile.o (the -stdlib=libc++ being the key difference). I think the default C++ runtime is the GNU implementation which is confusing the linker as you compiled … Read more

How to deal with global-constructor warning in clang?

Here is a simpler case that triggers the same warning: class A { public: // … A(); }; A my_A; // triggers said warning test.cpp:7:3: warning: declaration requires a global constructor [-Wglobal-constructors] A my_A; // triggers said warning ^~~~ 1 warning generated. This is perfectly legal and safe C++. However for every non-trivial global constructor … Read more