Struct - how to use this?

i have:
-normal c compiler
-SDL 1.1.3
-no fun with this fuck structs !!

got a problem:

how to use a structur if i declare it in main.h and later say:
below there is an example of my code -> if i include the declaration
of the struct in main.h into the main programm 1:1 and clear the line
extern struct test; out of main.c it works.
so - where is the problem ?

2nd question:
what means typedef struct??

DOES ANYBODY KNOW A PLACE WHERE I CAN GET A GOOD DOCUMENT ABOUT MY
USUAL PROBLEMS ?? IF SO - PLEASE MAIL IT TO ME !

============main.h=================
struct ObjectOnDisplay {
int cur_pos_x;
int cur_pos_y;
int cur_accel;
int cur_speed;
int max_speed;
int layer;
} test;==================================

=======main.c=====================
extern struct test;

test.cur_speed = 5;
printf("%d\n", test.cur_speed);


From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

Try this instead

============main.h=================
typedef struct {
int cur_pos_x;
int cur_pos_y;
int cur_accel;
int cur_speed;
int max_speed;
int layer;
} ObjectOnDisplay;==================================

=======main.c=====================

#include <main.h>

ObjectOnDisplay test;

test.cur_speed = 5;
printf("%d\n", test.cur_speed);

Typedef let’s you use your structs just like built in types. And try
to mello out a little in the future too, this message had loads of bad
karma :slight_smile:

Joachim Schiele wrote:

i have:
-normal c compiler
-SDL 1.1.3
-no fun with this fuck structs !!

got a problem:

how to use a structur if i declare it in main.h and later say:
below there is an example of my code -> if i include the declaration
of the struct in main.h into the main programm 1:1 and clear the line
extern struct test; out of main.c it works.
so - where is the problem ?

2nd question:
what means typedef struct??

DOES ANYBODY KNOW A PLACE WHERE I CAN GET A GOOD DOCUMENT ABOUT MY
USUAL PROBLEMS ?? IF SO - PLEASE MAIL IT TO ME !

============main.h=================
struct ObjectOnDisplay {
int cur_pos_x;
int cur_pos_y;
int cur_accel;
int cur_speed;
int max_speed;
int layer;
} test;

=======main.c=====================
extern struct test;

test.cur_speed = 5;
printf("%d\n", test.cur_speed);


From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

-no fun with this fuck structs !!
got a problem:

Enough now. This is not a mailing list for elementary C programming,
although people have been very patient and helpful so far. There are plenty
of books that can help you, and probably enough people in the real world who
you can ask.

Now go and learn C programming. A good book is Kernighan & Ritchie:
The C Programming Language. There should be a German translation.
You are welcome back here when you have SDL-related matters to discuss.

(Sorry for the harsh tone, but I get hundreds of mail every day and if
one more mailing list is lost in the noise, I have to abandon it.)

Joachim Schiele wrote:

i have:
-normal c compiler
-SDL 1.1.3
-no fun with this fuck structs !!

got a problem:

how to use a structur if i declare it in main.h and later say:
below there is an example of my code -> if i include the declaration
of the struct in main.h into the main programm 1:1 and clear the line
extern struct test; out of main.c it works.
so - where is the problem ?

2nd question:
what means typedef struct??

DOES ANYBODY KNOW A PLACE WHERE I CAN GET A GOOD DOCUMENT ABOUT MY
USUAL PROBLEMS ?? IF SO - PLEASE MAIL IT TO ME !

Buy a copy of Kernighan and Ritchie’s “The C Programming Language”.
It’s the standard reference. Also try looking in the comp.lang.c FAQ
list (look for it at http://www.faqs.org). A lot of your questions seem
to be those of newbie C programmers. Please, get yourself a good book
like the above described and save yourself the trouble of posting to the
list questions that are decidedly off-topic.

And typedef struct means you declare a type name to be a structure, so
that you don’t have to type struct name every time… For example, if
you say

typedef struct {
/* blah blah blah */
} test_struct;

you can instantiate it like this:

test_struct ts;

Whereas, without the typedef, like this:

struct test_struct {
/* blah blah blah */
};

You’d have to instantiate it this way:

struct test_struct ts;

Typedefs make for easier reading of code (and casts to the structure
type become easier as well), but are primarily a matter of coding style.–
Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
ICSM-F Development Team +63 (917) 4458925
University of the Philippines Diliman