구조체에 값을 할당 한 후 값을 읽으려고 할 때 이상한 프로그램 동작이 나타납니다. 내가 문제를 강조하기 위해 내 기능의 대부분을 주석 한할당 후 C에서 struture 값을 읽지 못했습니다.
/*Data struct for cor_entry */
struct cor_entry {
struct cor_entry * pre_entry;
struct cor_entry * next_entry;
long long unsigned int entry_data;
};
:
/* update correlation table */
void cor_table_update(long long unsigned int cor_table_data,
struct cor_entry **cor_table_head_ptr,
struct cor_entry **cor_table_tail_ptr,
int *entry_num,
const int MAX_NUM)
{
struct cor_entry *cor_table_entry;
int cor_hit=0;
//test code
//cor_table_head=cor_table_tail=(struct cor_entry*)calloc(1, sizeof(struct cor_entry));
//printf("original cor_entry_num=%d\n",*entry_num);
////////////////////////code for test///////////////////////////////
cor_table_entry=(struct cor_entry*)calloc(1, sizeof(struct cor_entry));
printf("The cor_table_entry=%x\n",cor_table_entry);
cor_table_entry->entry_data=cor_table_data;
if (cor_table_entry->entry_data==cor_table_data)
{
printf("The assignment is correct!\n");
printf("the cor_enrty_data=%x, stored data=%x,\n",
cor_table_data,
cor_table_entry->entry_data);
}
// ... rest of function
}
을하고 프로그램을 실행하는 동안 나는이 출력을 얻을 : 나는 아래의 관련 구조와 기능을 보여주는거야
을The cor_table_entry=8c09a58 The assignment is correct! the cor_enrty_data=8ffc8, stored data=0, The cor_table_entry=8c09a70 The assignment is correct! the cor_enrty_data=8ffc8, stored data=0, The cor_table_entry=8c09a88 The assignment is correct! the cor_enrty_data=8ffc8, stored data=0, The cor_table_entry=8c09ae8
누군가이 문제에 대해 밝힐 수 있습니까? 나는 GCC-3.4.6 컴파일러를 사용하고있다.
무엇을 기대 했습니까? 추신. 당신은 여분의 코드를 제거하고 싶을 수도 있습니다 –
나는 여기에있는 문제를 이해하지 못합니다 ... 출력에 따르면, 과제는 정확합니다! 'cor_table_data'는 0이 아니기 때문에 문제입니까? – filipe
@Martin @filipe 코드 읽기가 마음에 들지 않으면 의견을 남기지 마십시오. 문제는 분명하고 명확합니다. –