TwistedBlizzard
TwistedBlizzard

Reputation: 1006

How to define preprocessed global macros in Visual Studio 2022

I want to have a global macro in my program (PI 3.14). I read that you have to go to preprocessor->preprocessor definitions->edit and from there you can add your macros. But how do you actually set what the macro is?

I've added the macro PI in the top left. It shows up in my program as equaling 1. How do I make it equal 3.14?

enter image description here

Please forgive me if this is a bad question, I'm a bit new to visual studio and the preprocessor in general.

Upvotes: 0

Views: 2065

Answers (2)

Dan
Dan

Reputation: 1

Another way could be adding it to Preprocessor Definitions

_UNICODE;UNICODE;%(PreprocessorDefinitions);PI=3.14;FOO

Here I added PI with value 3.14 and FOO without an explicit value.

You can find it in you project properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.

I am 99% sure that it is identical to adding /D PI=3.14 to the additional options.

Upvotes: 0

Minxin Yu - MSFT
Minxin Yu - MSFT

Reputation: 4116

Please refer to the link:/D (Preprocessor Definitions)

/D name is equivalent to /D name=1.

use the way 273K said or in properties->C++->command line:

/D PI=3.14 

Upvotes: 1

Related Questions