You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your types are unnecessary - just use unsigned char and int as the standard library would.
On the same topic, your enum bool is unnecessary because in C non-zero indicates the true state. You confirm that yourself because get() assumes that the value 1 is true. Everyone assumes this and so the type is redundant. Moreover it is also wrong because if I change your enum to
typedef enum{true=0, false} bool;
your function fails, even though it is logically a reasonable thing to do.
If you want to use a bool like that your should return one of its values explicitly:
return ((a >> pos) & 1) ? true : false;
but there is really no point in this. Just return an int as the standard library would.
The text was updated successfully, but these errors were encountered:
Your types are unnecessary - just use unsigned char and int as the standard library would.
On the same topic, your enum bool is unnecessary because in C non-zero indicates the true state. You confirm that yourself because get() assumes that the value 1 is true. Everyone assumes this and so the type is redundant. Moreover it is also wrong because if I change your enum to
typedef enum{true=0, false} bool;
your function fails, even though it is logically a reasonable thing to do.
If you want to use a bool like that your should return one of its values explicitly:
return ((a >> pos) & 1) ? true : false;
but there is really no point in this. Just return an int as the standard library would.
The text was updated successfully, but these errors were encountered: