f3d32f00f9041628fe50f3c89bca813a8737c271
Generics/Metaprogramming in C
Exploring different ideas for implementing generics in C.
01_no_metaprogramming is the result of the code if implemented manually.
02_macros is an implementation that uses simple macros to define 2D and 3D vectors for different data types.
03_xmacros is an implementation that relies on X macros to allow for defining any N-dimensional vector for different data types. In this case, only 2D and 3D vectors were defined (for parity with the previous techniques), but it can be easily expanded to other dimensions.
General assessment of the different techniques
| Technique | Readability | Debugging | Maintenance | Extensibility | Applicability to other problems | Score (out of 5) |
|---|---|---|---|---|---|---|
| 01_no_metaprogramming | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐ | 2.60 | |
| 02_macros | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | 3.00 | |
| 03_xmacros | ⭐ | ⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | 2.20 |
Description
Languages
C
85.2%
C++
13.4%
Shell
1.4%