Wednesday, June 20, 2012

C PreProcessor and Intermediate C Code

# include <stdio.h>
# include <windows.h>

# define MAX 10


int main()
{
 static int nVariabe; // To understand the static variable constant
 int nloop=0;

    for (;nloop<MAX;nloop++)
    {
        nVariabe++;
        printf("%d static variable %d\n",nloop,nVariabe);

    }

 return 0;

}

 Please Check the For Condition .
From this code you will get the intermediate code information and understanding the C Macros.

Output for intermediate C code Generation




Static Variable Declaration without Data Type

# include <stdio.h>
# include <windows.h>

# define MAX 10


int main()
{
 static nVariabe; // To understand the static variable constant
 int nloop=0;

    for (;nloop<MAX;nloop++)
    {
        nVariabe++;
        printf("%d static variable %d\n",nloop,nVariabe);

    }

 return 0;

}

OUTPUT:

Here, everybody feels like compilation will abort. But, actual result is below,.
0 static variable 1
1 static variable 2
2 static variable 3
3 static variable 4
4 static variable 5
5 static variable 6
6 static variable 7
7 static variable 8
8 static variable 9
9 static variable 10

Note: We will get only Warning....

Description    Resource    Path    Location    Type
type defaults to `int' in declaration of `nVariabe'    Code.c    /intermediateCode    line 17    C/C++ Problem