The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+12 votes
814 views

The conditional expansion facility of macro processor is provided to

  1. test a condition during the execution of the expanded program
  2. to expand certain model statements depending upon the value of a condition during the execution of the expanded program
  3. to implement recursion
  4. to expand certain model statements depending upon the value of a condition during the process of macro expansion
asked in Compiler Design by Veteran (59.5k points)
edited by | 814 views

1 Answer

+14 votes
Best answer
Macro is expanded during the process of macro expansion. Hence, correct answer would be (d).
answered by Loyal (5.7k points)
selected by
0
Can u plz explain the meaning of conditional expansion facility of macro processor .
+10
#ifdef, #ifndef, #if defined etc. are the examples of conditional macros. These are evaluated and expanded during compile time (during the macro expansion phase of compiler).
0
referecne?
0

Conditional Compilation

There are a whole set of options that can be used to determine whether the preprocessor will remove lines of code before handing the file to the compiler. They include #if, #elif, #else, #ifdef, and #ifndef. An #if or #if/#elif/#else block or a #ifdef or #ifndef block must be terminated with a closing #endif.

The #if directive takes a numerical argument that evaluates to true if it's non-zero. If its argument is false, then code until the closing #else, #elif, of #endif will be excluded.

https://www.cprogramming.com/tutorial/cpreprocessor.html

0
Hello Aspi, I am showing how conditional macro is expanded with an example. Consider the following C program.

#include <stdio.h>

#if (X<3)
#define Y 3
#else
#define Y 300
#endif
int main()
{
    printf("Value of Y is %d\n", Y);
    return 0;
}

 

Now save the above program as example.c and compile in the following ways.

gcc -E -DX=1 example.c

gcc -E -DX=10 example.c

Observe the outputs of both compilations (printf statement), you will understand how conditional macros are expanded during preprocessing phase.


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,513 questions
46,665 answers
139,712 comments
57,486 users