Re: [ILUG] programming question

From: Vincent Cunniffe (vcunniff at domain arbgroup.com)
Date: Fri 17 Sep 1999 - 09:15:44 IST


caolan at domain 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



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:04:34 GMT