INCLUDE-ים בC...

neko

New member
INCLUDE-ים בC...

איך אני אמור להגידר בקובץ HEADER שלי את הSTRUCT והDEFINE האלה (של רשימה מקושרת אם זה מעניין מישהו)?
typedef struct cell { ... ... ... } Cell;​
הקומפיילר כל הזמן צועק עלי...
 

neko

New member
עכשיו חשבתי על זה שאולי מקומו

של כל הביטוי הנ"ל הוא בHEADER ולא בקובץ הSOURCE...
 

neko

New member
הנה מה שה &*!@^$&* אומר...

זה אחרי שסידרתי (כך נראה לי) את הSTRUCT והTYPEDEF כמו שצריך:
big_int_lib.c: In function `int freeBigInt(struct _big_int *)': big_int_lib.c:14: warning: implicit declaration of function `int free(...)' big_int_lib.c: In function `int createBigInt(struct _big_int **, char *)': big_int_lib.c:22: warning: implicit declaration of function `int malloc(...)' big_int_lib.c: In function `int writeBigInt(struct _big_int *)': big_int_lib.c:73: invalid use of undefined type `struct cell' big_int_lib.c:82: invalid use of undefined type `struct cell' big_int_lib.c:83: invalid use of undefined type `struct cell' big_int_lib.c:84: invalid use of undefined type `struct cell' big_int_lib.c:91: invalid use of undefined type `struct cell'​
 

neko

New member
נא להתעלם מהארבע טעויות הראשונות,

זה טופל (הוספתי INCLUDE MALLOC
)... אבל הוא ממשיך לא לזהות את הSTRUCT CELL שלי.
 

neko

New member
ממש לא...

זו הודעת השגיאה הרלוונטית: big_int_lib.c:73: invalid use of undefined type `struct cell' זה קובץ הHEADER הרלוונטי:
struct cell; typedef struct cell Cell; int insertCell(Cell* where, int n); Cell* makeEmpty(); void freeList (Cell* head); Cell* deleteZeroCells(Cell* head);​
הוא מזהה את Cell כ struct cell, אבל את struct cell עצמו הוא כנראה לא מזהה...
 
יכול להיות

הדבר הבא: ב-HEADER ששלחת אין הגדרה של CELL, אלא רק FORWARD DECLARATION שלו. נניח ובהמשך אתה מנסה לעשות שימוש ב-CELL, לדוגמה, לפנות לאיברים בתוכו או ליצור אובייקטים מסוג CELL וכו'. אז ברור ששורות קוד כאלה יכשלו, כי הקומפיילר עדיין לא קיבל שום מידע על CELL חוץ מה-FORWARD DECLARATION...
 

neko

New member
אני אמור להגדיר את cell בHEADER?

כלומר, לשים ממש את הקוד של:
struct cell { int num; cell* next; }​
בתוך קובץ הHEADER?
 

neko

New member
טוב נו, מסתבר שכן. עשיתי את זה

וזה עובד מושלם...
IO STUPIDO כבר אמרתי השבוע?
 
למעלה