精華區beta CSSE 關於我們 聯絡資訊
我想請教個困擾已久的問題…這問題讓我很久沒進度了。拜託有人能指點一下。 我首先有用到二個struct定義如下: struct obj_section{ int index; ElfW(Shdr) header; const char *name; char *contents; struct obj_section *next; }; struct obj_file{ ...略 struct obj_section **sections; ...略 }; 在程式的某處我已經對sections的空間做malloc了。 但是我在處理的過程中,又必須要動態的調整sections的空間大小,那 我用realloc function,可是…不知道怎麼回事,執行的時候一直aborted… 出問題的這行如下: struct obj_section *obj_create_alloced_section_first( struct obj_file *f, const char *name,unsigned long align, unsigned long size { struct obj_section *sec; …略 f->sections = realloc( f->sections,(newidx+1)*sizeof(sec) ); …略 } 出問題的又是第二個,就是括號裡頭的,f->sections,如果這個欄位改0,那OK,可以 run過去,但這樣…又不是我要的。 我要保留住先前的值… 拜託有任何idea的仁兄能給我點意見,感謝。 是空間不夠分了嗎…? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.15.123 ※ 編輯: mahaw 來自: 140.120.15.123 (02/28 18:23)