5 ms·
(Added msgf macro wrapper in above comment). I like it like that. It's also done like that in some codebases that I'm often skimming, e.g. the Linux kernel. I
by jstimpfle 4y ago
(Added msgf macro wrapper in above comment).
I like it like that. It's also done like that in some codebases that I'm often skimming, e.g. the Linux kernel. I don't worry about the standard in this case. As I've written more and more code, my willingness to do extra bullshit chores when there is no practical reason has been steadily decreasing.
Should you happen to choose an identifier that is already used by the host environment, you'll notice and can fix it. (It has literally never happened to me).
The intention here is that the prefixed variants are "private" i.e. they should not, or only rarely, be used directly. Instead, I use the macro layers to automatically fill in the right values and to improve safety. The above allows me to write
My_Foo *foo = xmalloc(My_Foo);
As you can see, there is very little boilerplate. Prefixing the implementation function makes it less likely to accidentally use them when doing code completion. The prefix nicely documents the relation between the macro and the inline function, and I don't have to bother coming up with a different name or naming scheme.
- SAI_Peregrinus 4y agoIt's Undefined Behavior by the C standard. So GCC (or other compiler) could use that for optimization, and omit the relevant lines or otherwise mess things up in weird ways. There's no guarantee that you'll notice, and no need for the identifier to be used by the host environment for it to cause a problem. That said, I'm not aware of any current compiler that does this. It'd be weird.