-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q: constructor/destructor functions? #46
Comments
I'm fine with the proposal in principle. But I would prefer it is named differently, e.g.
Secondly, if you want e.g. to just call Then you could just to do e.g. something like this: #define TEST_INIT { setlocale(... any args ...); } instead of the much more verbose void
my_init(void)
{
setlocale(... any args ...);
}
#define TEST_INIT my_init Finally, I am wondering whether the start/end of Unless you plan something time-expensive there, wouldn't it be better to call it from beginning/end of Or, perhaps, we could offer both? |
(Or maybe |
As using preprocessor is often tricky, especially when one wants to have it reasonably flexible and foolproof, I've played a little bit with it to see how the execute-the-macro pattern could look like. I have ended with this: #include <stdio.h>
// Test suite side:
// ================
//#define X /* empty definition */
//#define X printf("foo\n") /* single call; no semicolon */
//#define X printf("foo\n"); /* single call; with semicolon */
//#define X const char* str = "foo\n"; printf(str) /* using a var. declaration */
//#define X printf("foo"); printf("\n"); /* multiple calls */
//#define X { printf("foo"); printf("\n"); } /* a whole code block */
// Acutest side:
// =============
static void
call_X(void)
{
#ifdef X
X
#endif
;
}
int
main(int argc, char** argv)
{
call_X();
return 0;
} Notes:
Is it foolproof and flexible for practical use? Or any better idea? |
Sorry for disappearing. A stressful release led me to take a week's "holiday". |
Would you consider adding user-defined functions that'd be called at the beginning/end of
main()
Several of our tests need to have
setlocale()
called beforehand, so it'd be nice to centralise that.Something simple like:
If yes, I'll create a PR
The text was updated successfully, but these errors were encountered: