Why Task doesnt include FreeRTOS.h automatically

hello, i have simple question that is general about programming. im trying to learn from best practices programmers use in their daily life.

i noticed “Task.h” have the following snippet:

#error “include FreeRTOS.h must appear in source files before include task.h”

i don’t understand why not just include “freeRTOS.h” inside Task.h for example.

It is to make it more obvious what is going on - I have a personal preference not to include one header file from inside another because you can get yourself tied up on knots - but besides my preference formal coding standards (such as those for safety or security certifications) normally forbid nesting headers. In FreeRTOS there is one place where it can’t be avoided because you have to get the configuration file, portable header, and then the checks to see which configuration items are left undefined, all in the correct order.

1 Like