I'm looking to implement a generic temporary retry mechanism (retries only a set number of times) in C. I'm looking for similar functionality to the GNU TEMP_FAILURE_RETRY
macro.
What I have so far:
#define TEMP_RETRY_COUNT 10
#define TEMP_RETRY( exp ) \
({ \
int _attemptc_ = TEMP_RETRY_COUNT; \
bool _resultb_; \
while ( _attemptc_-- ) \
if ( _resultb_ = exp ) break; \
_resultb_; \
})
Works just fine. I'm trying to suppress the warnings the compiler warnings now and looking for something cleaner:
bleh.c: In function ‘main’:
bleh.c:38:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if ( TEMP_RETRY( bleh() ) )
^
bleh.c:46:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
TEMP_RETRY( bleh() );
Thank you for any replies! It needn't be a macro. Also, exp
can be presumed to return a boolean (or equivalent).