I would like to write the following function to return whether a queue is empty or not:
#include <stdbool.h> bool QueueIsEmpty(Queue *pq) { return (pq->items == 0)? true : false; }
Would doing the following shorthand work for this?
bool QueueIsEmpty(Queue *pq) { return pq->items == 0; }
In other words, does that return an int
or a bool
when doing the equivalency check? And if it returns a bool
how does the compiler know to cast it to a bool
, or is a bool just an int
behind-the-scenes?
When trying it in Compiler Explorer, both seem to just do mov eax, 0
and produce identical assembly: https://godbolt.org/z/bY59r3.
没有评论:
发表评论