*.h or *.hpp for your class definitions

Here are a couple of reasons for having different naming of C vs C++ headers: Automatic code formatting, you might have different guidelines for formatting C and C++ code. If the headers are separated by extension you can set your editor to apply the appropriate formatting automatically Naming, I’ve been on projects where there were … Read more

How do I detect unsigned integer overflow?

I see you’re using unsigned integers. By definition, in C (I don’t know about C++), unsigned arithmetic does not overflow … so, at least for C, your point is moot 🙂 With signed integers, once there has been overflow, undefined behaviour (UB) has occurred and your program can do anything (for example: render tests inconclusive).  … Read more

How can I get the list of files in a directory using C or C++?

UPDATE 2017: In C++17 there is now an official way to list files of your file system: std::filesystem. There is an excellent answer from Shreevardhan below with this source code: #include <string> #include <iostream> #include <filesystem> namespace fs = std::filesystem; int main() { std::string path = “/path/to/directory”; for (const auto & entry : fs::directory_iterator(path)) std::cout … Read more