C problem

hello. this has nothing to do with sdl, but sorry. i am trying to make a
global structure and i cant find anything on it. i tried extern struct
name, but
it didnt work. thanks!

hello. this has nothing to do with sdl, but sorry. i am trying to make a
global structure and i cant find anything on it. i tried extern struct
name, but
it didnt work. thanks!

In a header file:

typedef struct
{
   int myInt;
   char myString[100];
   /* or whatever you want in your structure. */
} MyStructureType;

extern MyStructureType mystruct; 

And in a C file:

MyStructureType mystruct;

The stuff in the header makes it globally known that the thing exists to
the rest of the program, and the mention in the one C file makes the
compiler allocate one structure of type MyStructureType, which will be
accessed by the rest of the program under the symbol mystruct.

You should get a good C tutorial off the web, as this really isn’t on
topic for an SDL mailing list.

–ryan.

go to www.programmersheaven.com

mfg upOn 21-May-01 Ryan C. Gordon wrote:

hello. this has nothing to do with sdl, but sorry. i am trying to make a
global structure and i cant find anything on it. i tried extern struct
name, but
it didnt work. thanks!

In a header file:

typedef struct
{
int myInt;
char myString[100];
/* or whatever you want in your structure. */
} MyStructureType;

extern MyStructureType mystruct;

And in a C file:

MyStructureType mystruct;

The stuff in the header makes it globally known that the thing exists to
the rest of the program, and the mention in the one C file makes the
compiler allocate one structure of type MyStructureType, which will be
accessed by the rest of the program under the symbol mystruct.

You should get a good C tutorial off the web, as this really isn’t on
topic for an SDL mailing list.

–ryan.

hello. this has nothing to do with sdl, but sorry. i am trying to make a
global structure and i cant find anything on it. i tried extern struct
name, but
it didnt work. thanks!

If this has nothing to do with SDL, why are you posting it here?

Anyway, to make a global struct, put this in a global header file:

typedef struct {
<members…>
} ;

extern ;

…Then, in a separate .c file (that does #include the above header)…

;

Note that the declaration of the struct in the separate .c file overrides
the `extern’ declaration.

Regards,

Alex.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20010520/2375f613/attachment.pgpOn Sun, 20 May 2001 23:44:07 +0000 Patrick McCarter wrote: