[問題] 當作 C語言 編譯執行時發生記憶體錯誤
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
CodeBlocks
問題(Question):
使用CodeBlocks編譯
若選C++則編譯成功
選C則跑出記憶體錯誤
新手求解~
謝謝大家
程式碼(Code):(請善用置底文網頁, 記得排版)
#define ERROR_FULL_W -1
#define ERROR_EMPTY_R -2
#define TRUE 0
#define FULL 1
#define EMPTY 1
#define UCHAR unsigned char
#define UINT unsigned int
struct Fifo{
UCHAR *m_buf;
UINT m_bufsize;//buffer size
UINT m_wp;
UINT m_rp;
UINT fullflag;
UINT emptyflag;
};
typedef struct Fifo CFifo;
void fFifoInit(CFifo *myfifo, UCHAR *tmp_buf, UINT tmp_size){
myfifo->m_buf = tmp_buf;
myfifo->m_bufsize = tmp_size;
fFifoEmpty(myfifo);
}
void fFifoEmpty(CFifo *myfifo){
myfifo->m_wp = 0;
myfifo->m_rp = 0;
myfifo->emptyflag = EMPTY;
myfifo->fullflag = !FULL;
}
int main()
{
//struct Fifo *myfifo;
CFifo *myfifox;
//UCHAR cnt = 0;
int i = 0;
int data = 0;
UCHAR data_buf[20];
fFifoInit(myfifox,data_buf,20);<<問題在此 是C和C++處理方式不同嗎
printf("Hello world!\n");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 27.241.218.160
※ 編輯: bxc 來自: 27.241.218.160 (11/07 14:57)
推
11/07 15:01, , 1F
11/07 15:01, 1F
推
11/07 15:05, , 2F
11/07 15:05, 2F
→
11/07 15:07, , 3F
11/07 15:07, 3F
推
11/07 15:37, , 4F
11/07 15:37, 4F
→
11/07 15:37, , 5F
11/07 15:37, 5F
謝謝回答 我想通了XDDD
※ 編輯: bxc 來自: 27.241.218.160 (11/07 15:47)
※ 編輯: bxc 來自: 27.241.218.160 (11/07 16:05)
推
11/07 17:35, , 6F
11/07 17:35, 6F
→
11/08 20:17, , 7F
11/08 20:17, 7F
推
11/10 01:52, , 8F
11/10 01:52, 8F
推
11/11 22:12, , 9F
11/11 22:12, 9F