C++ tips for project 8

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

C++ tips for project 8

Just finished my VM translator implementation in C++. Here are a couple of tips for people that want to use C++:

1. Listing files and directories: C++17 has a new header "filesystem" that will do just that. If your compiler doesn't support C++17 use Boost::filesystem, it is almost identical with the standard C++17 version.

2. Symbol tables, use the unordered_map from STL, you can use strings/numbers as keys.

3. Use "enum class" instead of the naked enum inherited by C++ from C. It is safer and will help you avoid mistakes.

4. Use vector instead of naked arrays, you will avoid most memory allocation errors this way.

5. Use the "cstdint" header that defines the "int16_t" type, it is easier to use same integer type as the Hack machine.