Removing functions from builds

Started by
13 comments, last by Helter Skelter 18 years, 9 months ago
I just tested your inline solution on my compiler (MSVC++ 7.1) on release mode and ran the disassembler and the there was no code related to the function at all, it even jumped a breakpoint I've set there, so you should be fine using inline.
Advertisement
I have an occasion used sizeof as the moral equivalent of __noop when such a thing was necessary and I could get away with it.
-Mike
One trick that provides the most compatibility across compilers is to do something like the following:

#ifdef _DEBUG#define FUNC(x) printf x#else#define FUNC(x)#endifvoid somefunction(char *ptr1, int val){    FUNC(("nothing to see here. %s - %d\n", ptr1, val));}


This comes in handy if you need to pass a variable number of arguments but need the code removed for release builds. You can also do something like the following to reduce the number of macros needed for calls that are only used once or twice:

#ifdef _DEBUG#define FUNC(x, y) x y#else#define FUNC(x, y)#endifvoid somefunction(char *ptr1, int val){    FUNC(printf, ("nothing to see here. %s - %d\n", ptr1, val));}

I'm wondering if the compiler will be okay handling more complex situations. Such as..

ScLog( SCLOG_WARNING, "%s %d %f", StringFunc(), rand() % 5, Time * 200.0f );

I can test it out. I'm just being lazy and can't remember where to find that ASM output option. I realize that some types of code in the parameter list would (or should) be included. But I wonder if that would actually be pulled out of the function argument list and called normally? It's no big deal, I'm just curious. I wouldn't include vital code in there anyways.

edit @ Helter Skelter: That's pretty clever. Another macro trick I was unaware of.
Quote:Original post by Jiia
edit @ Helter Skelter: That's pretty clever. Another macro trick I was unaware of.


Yeah it's pretty neat. Been using it for about a decade and I've only run into one compiler/preprocessor that didn't like it.

Also keep in mind that whether you use a FUNC like macro or the __noop directive statements like the following need to be avoided:

funcmacro(a++);


In release mode "a++" never happens. Now you would expect that the use of __noop would warn you about this but it doesn't.

This topic is closed to new replies.

Advertisement