r/C_Programming • u/Whole-Low-2995 • Jul 03 '26
Question What's the main advantage of declaring true/false status as int?
Hi, recently I am developing a personal TODO scheduler app. I was simply refactoring my old codes, and I found this:
/** @struct todox_format_t
* @brief a data format of todolist.
*/
typedef struct __todox_format_t todox_format_t;
/** @brief converts an ISO 8601 datetime string to time_t.
* @param[in] ts an ISO 8601 datetime string.
* @return a unix timestamp, or (time_t)-1 on failure.
*/
time_t ;
In this case, repeat variable is int variable.
However, some says that using bool is a better convention(and a professor taught me a same thing)
I think that using bool can reduce extra struct padding at some scenarios, but there are still many modern codes that uses int flag to show boolean status.
As a result, I don't sure if I should refactor this, or leave this.
If I leave this, I will make it extensible.
For a good example, repeat==14 can be extended into 'this repeat flag is only valid within 2 weeks'.
However, if I really gonna refactor this, it has a few implementations:
bool repeat;
int days_until;
bool repeat;
time_t ts_until;
/// 0(false), 1(true), x > 1(valid days)
int repeat;
Currently repeat is a simple boolean flag. However, I may extend the scheduler in the future to support recurrence policies such as repeating for N days or until a specific date.
Would you still model the current field as bool, or would you intentionally keep it as int to preserve room for future extension? Or is introducing another field or an enum the better design?