Skip to content

Instantly share code, notes, and snippets.

@alepez
Last active October 1, 2015 14:33
Show Gist options
  • Save alepez/65c5115a0b6f2b444b67 to your computer and use it in GitHub Desktop.
Save alepez/65c5115a0b6f2b444b67 to your computer and use it in GitHub Desktop.
static int aStrangeFunction() {
return ({ std::string xxx{"the answer is"}; 42; });
}
TEST(AStrangeFunction, AlwaysReturnTheAnswer) {
ASSERT_EQ(42, aStrangeFunction());
}
#define sys_errmsg(fmt, ...) ({ \
int _err = errno; \
errmsg(fmt, ##__VA_ARGS__); \
fprintf(stderr, "%*serror %d (%s)\n", (int)sizeof(PROGRAM_NAME) + 1,\
"", _err, strerror(_err)); \
-1; \
})
static int read_positive_ll(const char *file, long long *value)
{
// ...
if (close(fd))
return sys_errmsg("close failed on \"%s\"", file);
return 0;
out_error:
close(fd);
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment