Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Access violation writing exception (http://www.go4expert.com/forums/access-violation-writing-exception-t21720/)

arun10427 9Apr2010 23:27

Access violation writing exception
 
Hi,

I am writing a C program using VS2008 for easy debugging, but unfortunately I am running into access violation writing exception. When I executed step by step, I found that fscanf works for reading first few lines of the input text file, but throws access violation exception at a point. It would be great if someone can tell me what might fix this. I have been trying to fix this for long now and would really appreciate some help. The wierd part is it works on linux but I need VS2008 for debugging..

Code:

int address = 0;
int function_unit = 0;
int dest = 0;
int src1 =0;
int src2 =0;
void ifetch_decode_unit()
{
 
    if(cache_miss_flag==0 && count<10000)
    {
        fscanf(f1,"%x%d%d%d%d",&address,&function_unit,&dest,&src1,&src2);
      number++;
        int index = 0x000fe0;
        int tag = 0xfff000;
        index_entry = ((address&index)>>5);
        tag_entry = ((address&tag)>>12);
        if(cache[index_entry][0]==tag_entry)
        {
            cache_miss_flag = 0;
        }
        else
        {
        cache_miss_flag = 1;
        cache[index_entry][0] = tag_entry;
        }
    }   
    if(cache_miss_flag>0)
    {
        cache_miss_flag++;
        if(cache_miss_flag== 11)
        {
            cache_miss_flag = 0;
        }
    }
   
    if(cache_miss_flag == 0 && count<=10000)
    {
        if(fetched_instructions<=N)
        {
            //printf("\nNumber of fetched instructions at each step:\t%d\t%x",fetched_instructions,address);
            pipe.ifetchqueue[fetched_instructions].address = address;
            pipe.ifetchqueue[fetched_instructions].function_unit = function_unit;
            pipe.ifetchqueue[fetched_instructions].src1 = src1;
            pipe.ifetchqueue[fetched_instructions].src2 = src2;
            pipe.ifetchqueue[fetched_instructions].dest = dest;
            pipe.ifetchqueue[fetched_instructions].instruction_tag = number;
            fetched_instructions++;
        }
    }
}
void main()
{
   
    f1 = fopen("full_trace_barnes.txt","r");
    if(f1 == NULL)
    {
        printf("\n Unable to open the file. Aborting");
    }

    while(count<=10000)
    {
        count++;
        scheduling_type0();
        dispatch();
        ifetch_decode_unit();
        printqueues();
        cycle++;
    }
    if(count==10000)
        fclose(f1);
}


xpi0t0s 10Apr2010 14:45

Re: Access violation writing exception
 
Well you've only posted half the code, and you haven't posted the input file. Don't post the whole lot though: cut it down to the minimum needed to reproduce the problem, and post that. For example if you remove the calls to scheduling_type0(), dispatch(), ifetch_decode_unit() and printqueues(), replacing them with minimal "stub" code needed to let everything else work, and similarly replace the pipe.ifetchqueue statements, plus just enough of the the input file, then we may be able to help.


All times are GMT +5.5. The time now is 16:05.