RE: [ILUG] programming question

From: Caolan McNamara (Caolan.McNamara at domain ul.ie)
Date: Fri 17 Sep 1999 - 09:13:13 IST


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*/

>
>Vin
>
>--
>Irish Linux Users' Group: ilug at domain linux.ie
>http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
>List maintainer: listmaster at domain linux.ie

Real Life: Caolan McNamara * Doing: MSc in HCI
Work: Caolan.McNamara at domain ul.ie * Phone: +353-86-8790257
URL: http://www.csn.ul.ie/~caolan * Sig: an oblique strategy
What are you really thinking about just no?



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