warning image

It is a good programming practice –   if you optimize your source code , handle all type of memory leaks, remove the warnings,  document your code , provide better spacing, etc.

This provides another one to look into your code so easily.

Today, let me discuss something about WARNINGS.. 🙂

  • You can disable all the compiler warning using the compiler switch /w : Oh no.. this is so dangerous, and i think, this is a bad programming practice.
  • You can treat all warnings as errors using the switch /WX. : This is nice programming.. but it takes a lot of precious time to complete your app.
  • using /Wdn, you can disable the specified warning..

The default warning level for VS 2008 is Level 3, (i think so), but MSDN says

For a new project, it may be best to use /W4 in all compilations. This will ensure the fewest possible hard-to-find code defects. cool.. 🙂

suppose in a function like,

int DumpMe(int nCount, int nMode)
    return nCount++;

here, we are not using the variable nMode now, but at a later version of your app, you are going to use the nMode.

During compilation, definitely, you will  get the warning

warning C4100: 'nMode' : unreferenced formal parameter (if the warning level is 4)

Here to avoid that warning message, you can use 2 ways.

1. comment the nMode variable. like

int DumpMe(int nCount, int /*nMode*/)

2. Use the UNREFERENCED_PARAMETER macro. like


It’s just to suppress the warning – and the compiler will optimize it out since the code doesn’t do anything.

– For vctipsplusplus,