NO

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

Franzki

  • Guest
Exception: Access Violation
« on: June 04, 2009, 02:15:21 AM »
I started with more complex code but even this works (edit: to reproduce the crash):

Code: [Select]
int main(void)
{
double atest[5][5];

atest[4][4]=10;

return(0);

}

PellesC6 RC2

I haven't been able to compile my project to a working exe so I have to stay in version 5.
I'm using some structures with arrays of doubles and ints and the program sometimes crashes accessing them... though I think they are within valid memory space.
« Last Edit: June 04, 2009, 10:26:28 AM by Franzki »

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Exception: Access Violation
« Reply #1 on: June 04, 2009, 07:36:54 AM »
It seems that the optimzer optmizes away the intro of the function main, where the memory is allocated at the stack.  :(
« Last Edit: June 04, 2009, 08:27:05 AM by AlexN »
best regards
 Alex ;)

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Exception: Access Violation
« Reply #2 on: June 16, 2009, 09:07:12 PM »
I will see if I can reproduce it...
/Pelle

japheth

  • Guest
Re: Exception: Access Violation
« Reply #3 on: June 17, 2009, 06:19:14 AM »

I also got an access violation when I first tried PC v6rc2. Switching back to v5 helped.

There's no "stripped-down" test case, but the full project can be found at

http://www.japheth.de/download/jwasm196s.zip

To make it, run

pomake -f Pellesc.mak

and then pocc.exe "should" crash when compiling file tokenize.c

japheth

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #4 on: June 17, 2009, 10:13:32 AM »
In my situation the exe file that is created causes the Acces Violation. It's not the IDE that crashes...

japheth

  • Guest
Re: Exception: Access Violation
« Reply #5 on: June 17, 2009, 10:48:51 AM »
In my situation the exe file that is created causes the Acces Violation. It's not the IDE that crashes...

I'm sorry, I missed that. (Btw, it isn't the IDE, it's the compiler which crashes in my case.)

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #6 on: June 23, 2009, 01:08:21 PM »
Has anybody been able to reproduce this problem? (the compiler producing a crashing executable)

And is there a workaround available for Pelles 6 RC? I would really like to switch from my current Pelles 5 to 6 RC2 but I can't as long as my executables keep crashing.

nicolas.sitbon

  • Guest
Re: Exception: Access Violation
« Reply #7 on: June 23, 2009, 01:19:32 PM »
I confirm the bug, I found 2 workaround for the moment:
- initialize the table at declaration (
Code: [Select]
double atest[5][5] = {0};)
- in compiler option, disable all optimizations by setting to "none"

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Exception: Access Violation
« Reply #8 on: June 23, 2009, 01:29:15 PM »
Has anybody been able to reproduce this problem? (the compiler producing a crashing executable)

And is there a workaround available for Pelles 6 RC? I would really like to switch from my current Pelles 5 to 6 RC2 but I can't as long as my executables keep crashing.
You can switch off the optimizer. If you don't want to switch off the optmizer for the hole project you can try to switch on/off with #pragma optimize (none/time/size).
Code: [Select]
#pragma optimize(none)
int main(void)
{
double atest[5][5];
int i=0;
#pragma optimize(time)

atest[4][4]=10;

return(atest[4][4]);

}
or
Code: [Select]
int main(void)
{
static double atest[5][5];
int i=0;
atest[4][4]=10;

return(atest[4][4]);

}

And we have to wait for Pelles next version and test it then without #pragma or static.
« Last Edit: June 23, 2009, 01:33:58 PM by AlexN »
best regards
 Alex ;)

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #9 on: June 23, 2009, 01:45:58 PM »
Hello Alex,

Thank you for your quick reaction...

Disabling optimation solves the problem for the given example... but it doesn't seem to work for my project, it still ends with an "Access Violation" And this doesn't happen in de Pelles 5 version.

Could there be some optimation going on, even when selecting "none"?

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Exception: Access Violation
« Reply #10 on: June 23, 2009, 02:07:22 PM »
Thank you for your quick reaction...
If I have time, no problem.

Does the solution of nicolas.sitbon (he posted nearly at the same time) and the version with static also don't help you?

Can you find with the debugger the point, where the program crashes?
best regards
 Alex ;)

Franzki

  • Guest
Better code example (Exception: Access Violation in compiled .exe)
« Reply #11 on: June 23, 2009, 02:48:00 PM »
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]=tptr->jaarkosten[0]; //  this does not crash
tptr->jaarkosten[1]=tptr->jaarkosten[0]*3.25+0.5; // <- here the program crashes

}

To make it more clear I tried to simplify the code as I used it in my project.

Regards,
Frans

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Exception: Access Violation
« Reply #12 on: June 23, 2009, 02:54:40 PM »
You can not fill an integer variable with a floating point value without type casting or converting the float into an int.
---
Stefan

Proud member of the UltraDefrag Development Team

nicolas.sitbon

  • Guest
Re: Exception: Access Violation
« Reply #13 on: June 23, 2009, 02:56:47 PM »
It seems that enabling "microsoft extensions" corrects the problem (with or without optimization). Can anyone confirm?

Franzki

  • Guest
Re: Exception: Access Violation
« Reply #14 on: June 23, 2009, 02:59:22 PM »
Code: [Select]
tptr->jaarkosten[1]=(int)(tptr->jaarkosten[0]*3.25+0.5); // <- here the program crashes too
Hello Stephan,

I've tried that as well...  ;)