KAIST

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ KAIST ] in KIDS
글 쓴 이(By): Lobbyist (망각을 위�)
날 짜 (Date): 2001년 4월  3일 화요일 오후 04시 59분 09초
제 목(Title): [Q] C에서 realloc에 관한 문제



제가 이번에 석사논문으로 쓸 테마인데, 프로그래밍하다가 
물어볼 사람이 없어서 이렇게 글을 써서 도움을 청할려고 합니다. 

C에서 realloc에 관련된 문제입니다.

struct CHREQ_PACKET
{
    int     from_node;
    int     seq_num;
    int     s_id;
    int     d_id;
    int     hop_cnt;
    int     route_list[MAX_NUM];
    int     free_slot_list[SLOT_SIZE];
};

struct CHACK_PACKET 
{
int  from_node;              
int     seq_num;
int s_id;
int d_id;  
int hop_cnt;   
int route_list[MAX_NUM];
int reserved_slot_list[SLOT_SIZE];  
};

struct CHREQ_PACKET **chreq;
struct CHACK_PACKET **chack;

if ((double)t >= call_arr) 
{
chreq[m] = (CHREQ_PACKET *)malloc(sizeof(CHREQ_PACKET));
*chreq[m].from_node=s;

*chreq[m].seq_num=rand();
*chreq[m].s_id=s;
*chreq[m].d_id=d;
*chreq[m].hop_cnt=0;
*chreq[m].route_list[0]=s;
for(i=1; i<HOP_CNT_LIMIT; i++)
*chreq[m].route_list[i]=MAX_NUM;
for(i=0; i<SLOT_SIZE; i++)
*chreq[m].free_slot_list[i]=node[s].data[i].free;

node[s].req_transmitted+=1; 

m_prev = m;
m++;

call_arr += exp_dist(820.);   // another call_arrival 

} //if


문제 내용은 다음과 같습니다. 
if 절이 만족하면(call이 발생할때마다) chreq패킷을 발생시키는 작업인데, 
전체 시뮬레이션시간중 몇번의 패킷이 발생될지 몰라서 동적할당을 
시켜야되는데, 
몇번 할당될지몰라서 malloc를 쓰는게 아니라 realloc를 써야 합니다. 
근데 error C2228: left of '.from_node' must have class/struct/union type가 
나타납니다. 제가 알고 싶은번 call이 발생할때마다 chreq패킷을 
발생시켜야하고,
발생된 chreq패킷마다 서로 다르니깐 제가 따로따로 조작할 수 있어야 합니다.
잘 이해 안 가시면 그냥 제가 찾아뵙고 설명을 드릴테니, 이쪽으로 자신이 
있으시면
lobbyist@tmlab.kaist.ac.kr으로 연락주시면 고맙겠습니다.

여러 고수님들의 도움 부탁드립니다 ^^;


[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.