News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Exception: Access Violation

Started by Franzki, June 04, 2009, 02:15:21 AM

Previous topic - Next topic

Franzki

I started with more complex code but even this works (edit: to reproduce the crash):


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.

AlexN

#1
It seems that the optimzer optmizes away the intro of the function main, where the memory is allocated at the stack.  :(
best regards
Alex ;)

Pelle

I will see if I can reproduce it...
/Pelle

japheth


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

In my situation the exe file that is created causes the Acces Violation. It's not the IDE that crashes...

japheth

Quote from: Franzki 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...

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

Franzki

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

I confirm the bug, I found 2 workaround for the moment:
- initialize the table at declaration (double atest[5][5] = {0};)
- in compiler option, disable all optimizations by setting to "none"

AlexN

#8
Quote from: Franzki 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.
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).

#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

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.
best regards
Alex ;)

Franzki

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"?

AlexN

Quote from: Franzki on June 23, 2009, 01:45:58 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


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

Stefan Pendl

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

It seems that enabling "microsoft extensions" corrects the problem (with or without optimization). Can anyone confirm?

Franzki

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

Hello Stephan,

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