Problem mit cross-reference

OP Persönliche Seite #900533
Lesenswert?

Hallo,
Das Problem, was ich habe ist, dass zwei Strukturen jeweils Zeiger auf 
die jeweils andere Struktur haben:
1
struct tStruct1
2
{
3
    struct tStruct2* pStruct2;
4
};
5

6
struct tStruct2
7
{
8
    struct tStruct1* pStruct1;
9
};

Alles kein Problem, WENN man vor die Deklaration von tStruct1 folgendes 
voranstellt:
1
struct tStruct2;

Mein Problem ist aber, dass ich anynome Structs im Zusammenhang mit 
Typedefs benutze (Ist hiervon eigentlich abzuraten aus irgendwelchen 
Gründen?)
1
typedef struct
2
{
3
    tStruct2* pStruct2;
4
}tStruct1;
5

6
typedef struct
7
{
8
    tStruct1* pStruct1;
9
}tStruct2;

Was stelle ich jetzt voran?
1
typedef struct tStruct2;
funktioniert jedenfalls nicht:
warning: useless storage class specifier in empty declaration
1
typedef tStruct2;
auch nicht. Redefinition wg. Default int.
Persönliche Seite #900574
Lesenswert?

Hallo Simon,

Du musst in diesem Fall den Structs selbst auch Namen geben, anders 
gehts nicht:
1
struct tStruct2_tag;
2

3
typedef struct tStruct1_tag
4
{
5
    struct tStruct2_tag* pStruct2;
6
} tStruct1;
7

8
typedef struct tStruct2_tag
9
{
10
    struct tStruct1_tag* pStruct1;
11
} tStruct2;

bzw. auch:
1
struct tStruct2_tag;
2

3
struct tStruct1_tag
4
{
5
    struct tStruct2_tag* pStruct2;
6
};
7

8
struct tStruct2_tag
9
{
10
    struct tStruct1_tag* pStruct1;
11
};
12

13
typedef struct tStruct1_tag tStruct1;
14
typedef struct tStruct2_tag tStruct2;

Gruß,
Roland

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren