r/C_Programming • u/bore530 • May 26 '26
Question Is there a convention for `#define DEFINE`?
Had an idea recently for turning my files into symbols, here's an example from my code:
matchms.h
...
MATCH_API
#include <matchmem/matchms-define.func.h>
;
...
matchms.c
#define MATCHMS_C extern
#include <matchmem/matchms.h>
MATCH_API
#include <matchmem/matchms-define.func.h>
#include <matchmem/matchms-define.func.c>
...
matchms-define.func.h
match32d matchms_define
(
MATCHMS *ms,
_MATCHDST(matchcu,with)
)
matchms-define.func.c
{
MATCHMSENT *ents = withaddr;
memset(withaddr,0,withsize);
if ( withsize < sizeof(MATCHMSENT) )
{
memset(ms,0,sizeof(*ms));
return -1;
}
ms->data = ents;
ms->size = withsize;
ms->leng = sizeof(MATCHMSENT);
return 0;
}
And now I've thought to condense that a bit by combining matchms-define.func.h and matchms-define.func.c into one like this:
match32d matchms_define
(
MATCHMS *ms,
_MATCHDST(matchcu,with)
)
#ifdef DEFINE
{
MATCHMSENT *ents = withaddr;
memset(withaddr,0,withsize);
if ( withsize < sizeof(MATCHMSENT) )
{
memset(ms,0,sizeof(*ms));
return -1;
}
ms->data = ents;
ms->size = withsize;
ms->leng = sizeof(MATCHMSENT);
return 0;
}
#endif
#undef DEFINE
So I wanted to check if there was a convention for that particular macro before I go using it like this
Edit: Clearly a lot of peops can't adapt to new ideas, they don't even answer my question besides maybe one. Judging by their inability to accept the idea there's likely no convention so I'm going ahead with it, regardless of what the haters think :)
9
u/burlingk May 26 '26
Anything that obfuscates what your code is doing is risky.
4
u/DokOktavo May 26 '26
Don't subject yourself to criticism if you can't handle it.
There's no such convention, and for good reasons. That's it. Whether you want to try for yourself, learn from others experience or be completely blind to it is up to you.
7
u/markuspeloquin May 26 '26
The accepted convention is to do nothing at all like this.
3
u/Maqi-X May 26 '26
What's even the point of doing this
1
u/hyperficial May 27 '26 edited May 27 '26
It seems like what you're doing is similar to the *_IMPLEMENTATION macro from stb header files, but those still declare the function prototype beforehand
That said, I got confused reading your post because I thought the MATCH macros were part of your setup.