Your message tells me you have a fundamental lack of
understanding about variables.

A variable is a symbol that you declare to the compiler
as pointing to some chunk of information.  That chunk
could just as easily be a struct as it could one of the
primitive data types like int or char.  There is nothing
that restricts the use of extern to primitive data types.


FILE: structdef.h

struct mystruct {
    int field1;
    char field2[80];
};


FILE: globals.h
#include "structdef.h"
extern struct mystruct mystructvar;

FILE: main.c

#include "structdef.h"
#include "globals.h"

/* note: must allocate storage for extern var declared in "globals.h" */
struct mystruct mystructvar;

int func1() {
    StrCopy(mystructvar.field2, "using function func1() from file main.c");
}

FILE: other.c

#include "structdef.h"
#include "globals.h"

int func2() {
    StrCopy(mystructvar.field2, "using function func2() from file other.c");
}


--
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi/sec: not just a good idea, it's the LAW!


Eliah Ninyo wrote in message <[EMAIL PROTECTED]>...
>
>hi,
>
>i use a structure not a varible so i cann't use extern.
>i have a project with two files, when i put the typedef and define the
>structure fields in the second file i get an errors about a structure
>declaration. but when i declare another struct it's ok.
>
>it looks like it has something with my structure.
>for more details email me.
>
>byeee :-)
>"Charles Rezsonya" <[EMAIL PROTECTED]> wrote in message
>news:[EMAIL PROTECTED]
>>
>> hey,  why is it that a global shouldn't be shared across files? via
>extern?
>> i do this occasionally but haven't seen or heard issues with this (or
>> atleast what i seen).
>>
>> tia
>> Charles R
>>
>> -----Original Message-----
>> From: Fitzpatrick, Joe <[EMAIL PROTECTED]>
>> To: Palm Developer Forum <[email protected]>
>> Date: Monday, November 06, 2000 6:51 PM
>> Subject: RE: i have problem with my project...
>>
>>
>> >I'm not completely sure I understand you problem - but here are some
>> >generalities:
>> >
>> >If you are create a new data type (typdef or C++ class), the definition
>has
>> >to be included by all source files that use the type.  So, generally the
>> >definition goes in a shared .h file.
>> >
>> >If you are sharing a global variable between files (not a great idea,
but
>> >that is a huge subject) ONE source file (.c/.cpp) must instantiate the
>> >variable, all other source files that need the variable must include an
>> >'extern' declaration for the variable.
>> >
>> >File1.cpp:
>> >   mytype MyPublicVariable;
>> >
>> >File2.cpp:
>> >   extern mytype MyPublicVariable;
>> >
>> >There are games you can play with header files and defines to cut down
on
>> >repetition but, from the compiler's point of view the situation remains
>the
>> >same.
>> >
>> >Good Luck,
>> >-jjf
>> >
>> >-----Original Message-----
>> >From: Eliah Ninyo [mailto:[EMAIL PROTECTED]
>> >Sent: Sunday, November 05, 2000 1:08 PM
>> >To: Palm Developer Forum
>> >Subject: i have problem with my project...
>> >
>> >
>> >hello,
>> >
>> >i have a project with two files: file1.cpp and file2.cpp. i also have a
>> >header file, lets call it hand.h (in addition for the resources header
>> >file).
>> >
>> >i define a type def structure at file1. i needed the structure to be
>known
>> >at file2, so i put it un my header file - hand.h.
>> >i have in file2 line code in one of my function that looks like that:
>> >
>> >return strctP->field;
>> >
>> >strctP is define like this:
>> >
>> >mystructure *strctP;  // as a pointer to my structure
>> >
>> >field is one of the field in my struct.
>> >
>> >for some resone i get an error on this line (  - "return ...") saying "
>> >identifier expected".
>> >
>> >i really don't know what to do, why doesn't the '->' work?
>> >
>> >
>> >by the way, i use Code Warrior 6R.
>> >
>> >i hope some1 will know the answer because i real stuck.
>> >
>> >tnx :-)
>> >byeeeee
>> >
>> >
>> >--
>> >ELIAH NINYO
>> >
>> >[EMAIL PROTECTED]
>> >
>> >  ("`-''-/").___..--''"`-._
>> >  `6_ 6  )   `-.  (     ).`-.__.`)
>> >   (_Y_.)'  ._   )  `._ `. ``-..-'
>> > _..`--'_..-_/  /--'_.' ,'
>> >(il).-''  (li).'  ((!.-'
>> >
>> >
>> >
>> >--
>> >For information on using the Palm Developer Forums, or to unsubscribe,
>> >please see http://www.palmos.com/dev/tech/support/forums/
>> >
>> >--
>> >For information on using the Palm Developer Forums, or to unsubscribe,
>> please see http://www.palmos.com/dev/tech/support/forums/
>> >
>>
>>
>>
>
>
>
>





-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to