-3

My code looks something like this

while(!eof)
{
   if(A)
     doSomething;
   if(B)
     doSomething;
}

A and B are parameters from comand line. There may be also more parameters. I have struct of Bools, in which are all posible parameters and for every parameter, it determines if he exist or not.

Can i make compiler to not read the some part of the code?

I mean, in this code he will check for existence of B every iteration. What i want to achieve is that he will only check once

 if(B)
    doSomething;

I want this just to optimalize my program and i NEED to have both ifs in one cycle.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
rainmaker
  • 303
  • 1
  • 3
  • 13

1 Answers1

3

Frankly speaking, Ignoring part of code after compilation makes no sense. The code is already compiled. However. you can skip the execution of certain part of code using conditional statements, like if, else-if etc.

FWIW, "Command line parameters" are supplied and considered at run-time. There is no way you can decide (conditional compilation) based on that at compile-time.

However, if you want, you can always check the number of arguments (argc) supplied through command line and take action based on that.

Alternatively, if you wanted to have a conditional compilation, reading something about #ifdef/#ifndef may help.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261