Say I have this code (don't mind that SecondsToMinutes and MinutesToHours are copies of each other)
inline float SecondsToMinutes(float seconds) { return seconds / 60.0; } inline float MinutesToHours(float minutes) { return minutes / 60.0; } inline float HoursToDays(float minutes) { return minutes / 24.0; } inline float SeconndsToHours(float seconds) { return MinutesToHours(SecondsToMinutes(seconds)); } inline float MinutesToDays(float minutes) { return HoursToDays(MinutesToHours(minutes)); } inline float SeconndsDays(float seconds) { return MinutesToDays(SecondsToMinutes(seconds)); }
Is this a valid use of inline? Does this make sense? Is this a good practice? In the end, if I remember correctly, inline means that function calls are replaced by functional bodies, therefore
return MinutesToDays(SecondsToMinutes(seconds))
should be equivalent
return seconds / 60.0 / 60.0 / 24.0
Right?
Or is it better to use macros for this?
#define EXCHANGE_SEC_MIN(x) (x / 60.0) #define EXCHANGE_MIN_H(x) (x / 60.0) #define EXCHANGE_H_D(x) (x / 24.0) #define EXCHANGE_SEC_H(x) (EXCHANGE_MIN_H(EXCHANGE_SEC_MIN(x))) #define EXCHANGE_MIN_D(x) (EXCHANGE_H_D(EXCHANGE_MIN_H(x))) #define EXCHANGE_SEC_D(x) (EXCHANGE_MIN_D(EXCHANGE_SEC_MIN(x)))
Which one is better? Or not? I would like other cents on this.
source share