Color Blindness Test

Consider the following code:

Without colors:

int main(void)
{
 int x=100,y=20,res;
 int *p,p1;
 int *q;
 p=&x;
 q=&y;
 p1=p;

 res = *p/*q;

 /* redirect access  */
 *p1++;
 printf("res=%d\n",res);


 return 0;
}

And with colors:

int main(void)
{
 int x=100,y=20,res;
 int *p,p1;
 int *q;
 p=&x;
 q=&y;
 p1=p;

 res = *p/*q;

 /* redirect access  */
 *p1++;
 printf("res=%d\n",res);


 return 0;
}

it will print something useless

res=-1792611872

The problem here is with the line:

res = *p/*q;

p points to x (=100), q points to y (=20) so it should print res=5 but the statement parses as a comment because the it has /*

The compiler ignore the comment and because there is another real comment the line after it parses the statement like this :

res = *p * p1++;

Another problem is the line :

*p1++;

p1 is not a pointer , when we declare:

int * p,p1;

we declare p as pointer to integer and p1 as an integer, we don’t get any compiler error because it parsed here as multiply

Conclusion

Use colored editor for writing your code (forget about vi)