Include order: why must hal.h be included before hal_accelerometer.h, etc.?

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
dvchench
Posts: 1
Joined: Fri Oct 12, 2018 9:11 pm
Has thanked: 1 time

Include order: why must hal.h be included before hal_accelerometer.h, etc.?

Postby dvchench » Fri Oct 12, 2018 9:18 pm

I notice that hal_sensors.h does not include anything that provides _base_object_methods . Therefore, hal.h must be included before anything that inherits from hal_sensors.h . What is the reasoning behind this, or is this an oversight?

I normally organize my includes starting with "most local" first and "most global" see the accepted answer here for reasoning: https://stackoverflow.com/questions/276 ... -practices . Does Chibi have different guidance on this issue?

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Include order: why must hal.h be included before hal_accelerometer.h, etc.?

Postby Giovanni » Sat Oct 13, 2018 5:16 am

Hi,

There are tens of headers in HAL, all the common header are included in hal.h, the remaining ones depends on things imported by hal.h so are included afterward.

The pattern is, first hal.h then other HAL-related headers.

For simplicity we never hand-pick headers already included by hal.h, we just import the whole thing, the advantage is that if hal.h changes its internal organization then there are no dependencies to fix in other places.

halobject.h is one of those fundamental headers included by hal.h so it is not included separately.

Giovanni


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 23 guests