Access violation writing exception

This is a discussion on Access violation writing exception within the C Programming forums, part of the General Programming Boards category; Hi, I am writing a C program using VS2008 for easy debugging, but unfortunately I am running into access violation ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    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);
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    See post on devshed.com
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-13-2008, 03:51 AM
  2. Replies: 3
    Last Post: 07-17-2008, 09:45 AM
  3. Copying memory, pointers and the like.
    By psychopath in forum C++ Programming
    Replies: 34
    Last Post: 12-12-2006, 01:37 PM
  4. Help! CListCtrl access violation
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2003, 02:40 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 02:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21