Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] [C/C++] The use of #define, only preprocessor?

Status
Not open for further replies.

David_

Advanced Member level 2
Joined
Dec 6, 2013
Messages
573
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,308
Location
Sweden
Activity points
12,225
Hello.

While trying to learn something about macros I found that there are a directive #undef, and I wonder if the following:

Code:
#ifndef VALUE
#define VALUE 10
...
if(something)
{
    #ifdef VALUE
    #undef VALUE
    #define VALUE 20
}

Is this exclusively used as a preprocessor directive or can one use such a code during runtime to define things depending on button presses as a example?

Regards
 

can use #define in other than preprocessing section.
 

The preprocessing directives need not be defined in the top section of the code. They can used even inside your functions, but they wont be executed at 'runtime', the conditional preprocessing directives will be evaluated during compilation and be placed as some final value in compiled code.


Hello.

While trying to learn something about macros I found that there are a directive #undef, and I wonder if the following:

Code:
#ifndef VALUE
#define VALUE 10
...
if(something)
{
    #ifdef VALUE
    #undef VALUE
    #define VALUE 20
}

Is this exclusively used as a preprocessor directive or can one use such a code during runtime to define things depending on button presses as a example?

Regards
 

can one use such a code during runtime to define things depending on button presses as a example?

NO, pre-processor works before compiling result, so
you only can prepare some conditional compiling option ..

to modify the behavior or your application during runtime, .. just code it , with your external events ..
Code:
 if( BP1==1) 
{
 do something
 use UART1 ...
  }
else
 {
  do other job
  use LCD ..
 }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top