NO

Author Topic: Exception: Access Violation  (Read 14462 times)

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #15 on: June 23, 2009, 03:01:15 PM »
Hello Nicolas...

You seem to be right about enabling the "Microsoft Extensions"

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #16 on: June 23, 2009, 10:53:41 PM »
Ok...

As far as I can see there seem to be 2 issues over here causing a runtime Access Violation error in PellesC 6RC2.

The first one:
Code: [Select]
void main()
{
  double atest[5][5];

  atest[4][4]=10;  // <- here the program crashes
}
This one can be avoided by disabling the compiler optimations.

The second one:
Code: [Select]
typedef struct K_REGEL
{
int jaarkosten[10];
} K_REGEL;

void main()
{
  K_REGEL rekenblad;
  K_REGEL * tptr;
  tptr=&rekenblad;
  int i;

  for(i=0;i<10;++i)
    rekenblad.jaarkosten[i]=0;

  tptr->jaarkosten[1]=(int)(tptr->jaarkosten[0]*3.25+0.5); // <- here the program crashes
}
This one can be avoided by enabling "microsoft extensions".

I hope Pelle is reading this and can shine his light on both issues.

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Exception: Access Violation
« Reply #17 on: June 24, 2009, 07:52:36 AM »

The second one:
Code: [Select]
typedef struct K_REGEL
{
int jaarkosten[10];
} K_REGEL;

void main()
{
  K_REGEL rekenblad;
  K_REGEL * tptr;
  tptr=&rekenblad;
  int i;

  for(i=0;i<10;++i)
    rekenblad.jaarkosten[i]=0;

  tptr->jaarkosten[1]=(int)(tptr->jaarkosten[0]*3.25+0.5); // <- here the program crashes
}
This one can be avoided by enabling "microsoft extensions".

For this one you can look into Pelles help file, for the extensions witch are enabled by this option.
One of this extensions is:
"Converting a floating-point number to signed int or long will chop rather than limit the value."
best regards
 Alex ;)

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #18 on: July 13, 2009, 01:07:20 AM »
Ok...

As far as I can see there seem to be 2 issues over here causing a runtime Access Violation error in PellesC 6RC2.

The first one:
Code: [Select]
void main()
{
  double atest[5][5];

  atest[4][4]=10;  // <- here the program crashes
}
This one can be avoided by disabling the compiler optimations.

The second one:
Code: [Select]
typedef struct K_REGEL
{
int jaarkosten[10];
} K_REGEL;

void main()
{
  K_REGEL rekenblad;
  K_REGEL * tptr;
  tptr=&rekenblad;
  int i;

  for(i=0;i<10;++i)
    rekenblad.jaarkosten[i]=0;

  tptr->jaarkosten[1]=(int)(tptr->jaarkosten[0]*3.25+0.5); // <- here the program crashes
}
This one can be avoided by enabling "microsoft extensions".

I hope Pelle is reading this and can shine his light on both issues.

Here's some good and some bad news...

Both samples (as far I could check) now both compile to a working executable in PellesC 6RC3. So it seems that Pelle managed to find and fix the problems regarding the code examples I posted.

The bad news is that my project still crashes with an Access Violation error. Workaround is enabling "Microsoft extensions".

There seems to be something going wrong with some combination of pointers, structures, arrays and float-to-int (or double-to-int) conversions in my project, causing Access Violation errors.

- No problems in PellesC 5
- No problems in other compilers (for example code::blocks)
- No problems in PellesC 6RC3 when enabling Microsoft Extensions

My full project is too big to post it here... I'm not sure if I can extract the essential code to reproduce the error.

Getting a bit desperate..  ???
« Last Edit: July 13, 2009, 01:13:31 AM by Franzki »

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Exception: Access Violation
« Reply #19 on: July 13, 2009, 08:40:41 AM »
- No problems in other compilers (for example code::blocks)
Code::Blocks is not a compiler, it is just an IDE but usually bundeled with MinGW GCC as compiler. ;)

My full project is too big to post it here... I'm not sure if I can extract the essential code to reproduce the error.
Do you have the possibility to put the source-code on a server and send us the link?
best regards
 Alex ;)

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #20 on: July 13, 2009, 09:27:29 AM »
- No problems in other compilers (for example code::blocks)
Code::Blocks is not a compiler, it is just an IDE but usually bundeled with MinGW GCC as compiler. ;)

My full project is too big to post it here... I'm not sure if I can extract the essential code to reproduce the error.
Do you have the possibility to put the source-code on a server and send us the link?

Yes im using Code::Blocks with the MingW GCC compiler  ;)

I could put the code somewhere on a server but I prefer to strip it down to the essention... I will see what I can do  :P

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #21 on: July 13, 2009, 10:31:37 AM »
Code: [Select]
typedef struct K_REGEL
{
int jaarkosten[10];
} K_REGEL;

int main()
{
  K_REGEL rekenblad;
  K_REGEL * tptr;
  tptr=&rekenblad;
  int i;

  for(i=0;i<10;++i)
    rekenblad.jaarkosten[i]=0;

  tptr->jaarkosten[1]=(int)(tptr->jaarkosten[0]*3.25+0.5); // <- here the program crashes

  return(0);
}

I though all problems were gone with this piece of code...

It causes NO Access Violations when compiled with "default" console project settings in Pelles C 6RC3.

Though with optimation turned off it has an Access Violation again.

This can be avoided by enable Microsoft Extension when optimation is turned off.

By the way... this isn't my real problem with my project but I noticed it when I was trying to narrow down the other problems.

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Exception: Access Violation
« Reply #22 on: July 13, 2009, 02:04:49 PM »
Code: [Select]
typedef struct K_REGEL
  tptr->jaarkosten[1]=(int)(tptr->jaarkosten[0]*3.25+0.5); // <- here the program crashes
}

The compiler creates  without optimizing the following code for this line:
Code: [Select]
mov eax,dword [ebp+(-44)]
fild dword [eax]
fmul qword [(@10)]
fadd qword [(@11)]
fstp qword [ebp+(-56)]
fld qword [ebp+(-56)]
call ___ftol
mov edx,eax                                 // save the result of ___ftol from EAX of to EDX
mov dword [eax+(4)],edx                // store the result to ??? ;)

I think Pelle has to look at this.
best regards
 Alex ;)