Technical Journal

Programming, software technologies, operating systems, IT

C++ UNREFERENCED_PARAMETER

I am currently developing a driver for one of our custom made devices under Windows CE and I came across this macro -

UNREFERENCED_PARAMETER in one of the driver examples I took as reference for developing my own. The definition itself does not say much:

#define  UNREFERENCED_PARAMETER(P) (P)

All it does is to layout the parameter or expression it has been passed. After some browsing on the internet I’ve found this post by Paul DiLascia:

http://msdn.microsoft.com/en-us/magazine/cc163805.aspx which I think greatly explains what is meant by compiling with Warning Level 4 – it made me a believer anyway.

Indeed, an unreferenced parameter would cause an error when compiling using level 4 and this is where UNREFERENCED_PARAMETER comes in handy.

For instance you have a function like this:

void foo( int arg1, float arg2 )

{

     UNREFERENCED_PARAMETER( arg1 );

}

Since you won’t be using arg1 and also you will compile with level 4, you just fool the compiler by passing arg1 as parameter to a macro that just adds the line:

arg1;

to your code. And since it is not used the compiler does not generate code for it and no efficiency or space is lost.

I will not repeat here stuff written in that post, just thought I’d mention it as a great post on C++ I’ve found.

April 7, 2009 - Posted by andocs | Programming | , | No Comments Yet

No comments yet.

Leave a comment