[ILUG] programming question

Vincent Cunniffe vcunniff at arbgroup.com
Fri Sep 17 09:15:44 IST 1999


caolan at metasyntax.idc.ul.ie wrote:
> 
> On 17-Sep-99 Vincent Cunniffe wrote:
> >Problem :
> >
> >I want to compile a single executable from two separate source files, both
> >of which need access to the data definitions, such as structures.
> >
> >I can 'extern' the actual data definitions themselves, but the structs refuse
> >to be 'extern'ed, and the compiles fail on duplicate definitions.
> >
> >Solution :
> >
> >typedef?
> 
> Nothing to it at all, heres one sample using typedefs, header for the def,
> extern in one and normal in the other.
> 
> /*a.h begin*/
> typedef struct _arse
>         {
>         int a;
>         }fish;
> /* a.h end */
> /* a.c begin */
> #include "a.h"
> 
> fish cod;
> 
> void main(void)
>         {
>         cod.a = 4;
>         test();
>         printf("%d\n",cod.a);
>         }
> /* a.c end */
> /* b.c begin */
> #include "a.h"
> 
> extern fish cod;
> 
> int test(void)
>         {
>         cod.a = 5;
>         }
> 
> /* b.c end*/

Figured it'd be something like that, but I'd forgotten the syntax for
typedefs and couldn't find my copy of Stroustrup ;-)

Cheers.

Vin




More information about the ILUG mailing list