I'm working on a medium embedded application in C using OO-like techniques. My classes are .h/.c modules using data structs and function pointers structs to emulate encapsulation, polymorphism, and dependency injection.Now, one would expect a myModule_create(void) function to come with a myModule_destroy(pointer) counterpart. But the project being embedded, the resources that are instantiated realistically should never be released.I mean, if I have 4 UART serial ports and I create 4 UART instances with their required pins and settings, there's absolutely no reason to ever want to destroy UART #2 at some point during runtime.So following the YAGNI (You ain't gonna need it) principle, should I omit the destructors? This seem extremely strange to me but I can't think of a use for them; resources are freed when the device powers-off.
Omitting destructors in C is taking YAGNI too far?
c;embedded systems
If you don't provide a way to dispose the object, you are passing a clear message that they have infinite lifetime once created. If this makes sense to your application, I say: do it.Glampert is right; there is no need for destructors here. They would just create code bloat and a pitfall for users (using an object after its destructor is called is undefined behavior).However, you should be sure that there is really no need to dispose of the objects. For instance, do you need to have an object for a UART that is not currently in use?