[prog] Solution

Mari Wang mariw at acm.org
Fri Jan 31 21:41:57 EST 2003


[Elizabeth Barham]

> "Sachin" writes:
> 
> Hi Sachin,
> 
>    The most glaring error of your code is the odd use of defining
> certain header file symbols (such as _STDIO_H for <stdio.h>) prior to
> including the header file itself.
> 
> from COMM.H:
> 
>         /* FOR PRINTF AND SCANF FUNCTIONS */
>         #ifndef  STDIO_H
>                 #define _STDIO_H
>                 #include<stdio.h>
>         #endif

[snip]

Without having had a look at the source in this case, I suspect this
might have been added to avoid recursively including header files.  A
very common practice to avoid this is to encapsulate ones header files
in ifdefs specific to each header file.  As an example, a header file
from a previous project I was working on looks like this (the file is
named createimage.h):

#ifndef CREATEIMAGE_H
#define CREATEIMAGE_H

[snip actual header code]

#endif

This way you'll avoid the problem once and for all. :)

Mari :)

-- 

Mari Wang - mariw at acm.org



More information about the Programming mailing list