2019-07-08 01:52 AM
I am not sure how to ask but some functions in HAL libraries, just starts with HAL prefix, for example
HAL_GPIO_WritePin() ;
But also some macros start with double underscores for example
__HAL_GPIO_EXTI_CLEAR_IT()
I know that ones are macros and others are functions but is there a reason why they are used this style ?
Thanks.
Solved! Go to Solution.
2019-07-08 03:23 AM
I just indicated the existence of the paradigm, but whether ST engineers are using the double underscore for that or something else I can't tell. If the function/macro is documented and is being used in ST-provided examples then I think you can safely use them, underscore or not.
P.S.
From Wikipedia:
An underscore as the first character in an ID is often used to indicate internal implementation that is not considered part of the API and should not be called by code outside that implementation. Python uses this for private member variables of classes, this is common in other languages such as C++ even though those provide keywords to indicate that members are private. It is extensively used to hide variables and functions used for implementations in header files. In fact the use of single underscore for this became so common that C compilers had to standardize on a double leading underscore (for instance __DATE__) for actual built-in variables to avoid conflicts with the ones in header files.
2019-07-08 02:18 AM
It's an old known programming paradigm used to indicate that the variable/macro/function/etc is for private use (used by the library itself, not to be used by the end-user), thus you can't rely on it to not break in the next version.
2019-07-08 02:30 AM
So at any part of coding, If the library is well-designed, I don't have to use the ones with "__" right? There should be a function doing the same thing ?
Thanks.
Edit : I think what I thought is wrong, because for example I can't find a function which makes the job of
#define __HAL_TIM_GET_COUNTER(__HANDLE__) \
((__HANDLE__)->Instance->CNT)
2019-07-08 03:23 AM
I just indicated the existence of the paradigm, but whether ST engineers are using the double underscore for that or something else I can't tell. If the function/macro is documented and is being used in ST-provided examples then I think you can safely use them, underscore or not.
P.S.
From Wikipedia:
An underscore as the first character in an ID is often used to indicate internal implementation that is not considered part of the API and should not be called by code outside that implementation. Python uses this for private member variables of classes, this is common in other languages such as C++ even though those provide keywords to indicate that members are private. It is extensively used to hide variables and functions used for implementations in header files. In fact the use of single underscore for this became so common that C compilers had to standardize on a double leading underscore (for instance __DATE__) for actual built-in variables to avoid conflicts with the ones in header files.