preprocessor definition in visual studio


What should be put in the preprocessor definition (in visual studio) and who should put it?

Is the purpose of the preprocessor definition to allow the programmer/user to put in certain "macros" such that inside the classes, the use can check against the macro and execute different commands.

For example, as a programmer puts ICECREAM in the preprocessor and then inside the .cpp file, he does a check
  //do this
 //do that

Is there anything else that the preprocessor is used for? Is this also the correct way to use the preprocessor i.e. using it in the spirit of what it was meant for?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karrtik IyerSoftware ArchitectCommented:
Some pre-processor statements come default with any new project of visual studio such as Windows SDK version, OS version. In addition _DEBUG, _RELEASE variables that state which configuration of build is being currently used.
In addition these can be defined by the developer as well.
These pre-processor statements are mostly used for conditional compilation, where in you want to compile a piece of code only if certain pre-processor variables are defined.
Such as if you may want to check if something is installed, or if windows OS is 7 then use power shell.
Also pre-processor are used in header files to ensure things are declared only once (similar to pragma once), like below
Contents of MyHeader.H
#ifndef _MY_HEADER_H
#define _MY_HEADER_H
//Class declaration and variable declarations goes inside this file

Please let me know if something is still unclear.

>>Is there anything else that the preprocessor is used for?

Since you now know about conditional compilation - an important part of the work a PP does - the article at will address the big picture. Or, in a nutshell, the preprocessor is responsible for

including files specified in a #include directive
perform conditional compilation (as Karrtik Iyer has already explained)
expands macros that have been defined earlier
process user-defined error and warning messages (mostly toghether with conditional compilation)
addressed compiler-specific preprocessor features

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.