Voor een programma is het nodig om een structure samen met een paar andere variabelen aan een functie mee te geven. Dit lukt wel als de struct de enige variabele is, maar niet als ik bijvoorbeeld ook nog een int wil meegeven. In het C boek dat ik gebruik staat er niks over dat dit wel/niet kan. Kan iemand mij vertellen hoe ik dit probleem kan oplossen? Ik wil het liefst geen globale variabelen meesturen. Onderstaande code is een simpel programmaatje met hetzelfde probleem.
Alvast bedankt!
passStruct.c:4: warning: `struct test_struct' declared inside parameter list
passStruct.c:4: warning: its scope is only this definition or declaration, which is probably not what you want
passStruct.c: In function `main':
passStruct.c:17: warning: passing arg 2 of `test1' from incompatible pointer type
passStruct.c: At top level:
passStruct.c:22: conflicting types for `test1'
passStruct.c:4: previous declaration of `test1'
.modbreak: code gehighlight en compiler errors buiten code tag gezet, zodat de layout niet wordt verneukt
Alvast bedankt!
C:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| #include <stdio.h> /* Function declarations */ void test1(int i, struct test_struct *testStruct); /* Struct containing the info */ struct test_struct { int test; }; int main(void) { int i = 99; struct test_struct testStruct; // Initialise the struct testStruct.test = 100; // Call the function that receives the int & struct test1(i, &testStruct); return 0; } void test1(int i, struct test_struct *testStruct) { printf("Values: %d %d.\n", i, testStruct->test); } |
passStruct.c:4: warning: `struct test_struct' declared inside parameter list
passStruct.c:4: warning: its scope is only this definition or declaration, which is probably not what you want
passStruct.c: In function `main':
passStruct.c:17: warning: passing arg 2 of `test1' from incompatible pointer type
passStruct.c: At top level:
passStruct.c:22: conflicting types for `test1'
passStruct.c:4: previous declaration of `test1'
.modbreak: code gehighlight en compiler errors buiten code tag gezet, zodat de layout niet wordt verneukt
[ Voor 10% gewijzigd door .oisyn op 10-03-2003 14:35 ]