#define fst 1
int main()
{
     #if( fst ==1 )
               printf("FST\n");
     #else 
              printf("Dummy FST\n");
 return 0;
}

if i replace the statement in line 4 with #if fst also the code is working.

can any one tell me what is the correct way , advantages and disadvantages.

You forgot the #endif The correct way of doing what? What are you trying to do?

You forgot the #endif The correct way of doing what? What are you trying to do?

i am trying to use conditional macro , and want to check a defined value as in line number 4.

i used #if ( fst == 1) then the code is working and if i replace the statement #if ( fst == 1) with #if fst then also the code is working .

i just want to know which one is correct and good to use.

You should be using

#ifdef fst

in your code check instead of

#if (fst == 1)
#define fst 1

The above line is an indicator to replace fst with 1 whenever seen.

So (fst == 1) translates to (1==1)

The #define is used for many purposes like ,
1)For defining constants.
2)For conditional excution of code.
3)For making sure that multiple inclusions of header files are avoided.

You can also write macro code using this directive.

I tend to use this type of construct:

#if defined MACRO && MACRO > 0

because you really shouldn't be doing this

#if MACRO > 0

if MACRO is not defined.

And just doing

#ifdef MACRO

or

#if defined MACRO

would be true even if MACRO were defined as 0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.