I have encoutered a problem "General Protection Exception" when trying to run this program, I need a help on a urgent basis:
the code: -
#include <stdio.h>
-
#include <stdlib.h>
-
-
#define L 20
-
#define V 30
-
#define O 2
-
#define N 4
-
-
struct Element
-
{
-
unsigned int c[L];
-
int value ;
-
};
-
-
struct Variable
-
{
-
struct Element e[V] ;
-
double y[V] ;
-
double f[O] ;
-
};
-
-
void initializeElement(struct Element*);
-
-
void main(void)
-
{
-
Variable *x ;
-
int i,j ;
-
x = (struct Variable*)malloc(sizeof(struct Variable) * N);
-
-
for( i = 0 ; i < N ; i++ )
-
{
-
for( j = 0 ; j < V ; j++ )
-
{
-
initializeElement(&(x[i].e[j]));
-
x[i].y[j] = 0 ;
-
x[i].f[j] = 0 ;
-
}
-
-
for( j = 0 ; j < O ; j++ )
-
x[i].f[j] = 0 ;
-
}
-
}
-
-
-
void initializeElement( struct Element *e)
-
{
-
int i, r ;
-
for( i = 0 ; i < L ; i++ )
-
{
-
r = rand() % 1000 ;
-
if( r < 500 )
-
e -> c[i] = 0 ;
-
else
-
e -> c[i] = 1 ;
-
}
-
e -> value = 0 ;
-
}
-
Plz help anyone as soon as possible.
6 1629 AdrianH 1,251
Recognized Expert Top Contributor -
{
-
initializeElement(&(x[i].e[j]));
-
x[i].y[j] = 0 ;
-
x[i].f[j] = 0 ;
-
}
-
Just by inspection, I would say it is the x[i].f[j] = 0 ; line, since j could be between 0 and V which is defined as 30 and f has only O elements which you defined O as 2.
You've been looking at the code too long. :)
Adrian
DeMan 1,806
Top Contributor
You've been looking at the code too long. :-)
Ain't that the truth way too often
I have encoutered a problem "General Protection Exception" when trying to run this program, I need a help on a urgent basis:
the code: -
#include <stdio.h>
-
#include <stdlib.h>
-
-
#define L 20
-
#define V 30
-
#define O 2
-
#define N 1024
-
-
struct Element
-
{
-
unsigned int c[L];
-
int value ;
-
};
-
-
struct Variable
-
{
-
struct Element e[V] ;
-
double y[V] ;
-
double f[O] ;
-
};
-
-
void initializeElement(struct Element*);
-
-
void main(void)
-
{
-
Variable *x ;
-
int i,j ;
-
x = (struct Variable*)malloc(sizeof(struct Variable) * N);
-
-
for( i = 0 ; i < N ; i++ )
-
{
-
for( j = 0 ; j < V ; j++ )
-
{
-
initializeElement(&(x[i].e[j]));
-
x[i].y[j] = 0 ;
-
//x[i].f[j] = 0 ;
-
}
-
-
for( j = 0 ; j < O ; j++ )
-
x[i].f[j] = 0 ;
-
}
-
}
-
-
-
void initializeElement( struct Element *e)
-
{
-
int i, r ;
-
for( i = 0 ; i < L ; i++ )
-
{
-
r = rand() % 1000 ;
-
if( r < 500 )
-
e -> c[i] = 0 ;
-
else
-
e -> c[i] = 1 ;
-
}
-
e -> value = 0 ;
-
}
-
Plz help anyone as soon as possible.
If I ommit that line, still the problem exists. if N < 40 then it is ok, but when I put N = 1024, same General Protection Exception occurs. What'll I do?
AdrianH 1,251
Recognized Expert Top Contributor
If I ommit that line, still the problem exists. if N < 40 then it is ok, but when I put N = 1024, same General Protection Exception occurs. What'll I do?
Are you using g++? Perhaps you have gdb installed there as well? Try looking at this post. It will briefly explain how to use it to debug your programme. You may try and run the programme in the debugger, and if the exception occurs, depending on the severity, it may tell you where the problem is. Otherwise a stepping approch as describe there may be your only way.
If you still have problems, I will try and help you further.
Adrian
Are you using g++? Perhaps you have gdb installed there as well? Try looking at this post. It will briefly explain how to use it to debug your programme. You may try and run the programme in the debugger, and if the exception occurs, depending on the severity, it may tell you where the problem is. Otherwise a stepping approch as describe there may be your only way.
If you still have problems, I will try and help you further.
Adrian
Thanx, I think my problem is finished. I found no exception now using g++/gcc
AdrianH 1,251
Recognized Expert Top Contributor
Thanx, I think my problem is finished. I found no exception now using g++/gcc
Ohh, problems that go away by themselves. I hate those. I never know if the problem has truely gone away or just not showing itself.
If you recompiled a clean copy, it could be that you had a phase error in your compilation. This happens when one source file that depends on another source or header file doesn't get recompiled when the files it depends on have been.
I hate that when it happens.
Adrian
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: SteveS |
last post by:
Hello all. This problem is stumping me.... I run a page called
"default.aspx". For some reason when I execute this page, I get the error
below. It seems to run through the entire code behind...
|
by: Antoon Pardon |
last post by:
I was wondering how people would feel if the cmp function and
the __cmp__ method would be a bit more generalised.
The problem now is that the cmp protocol has no way to
indicate two objects are...
|
by: Paiman Allage |
last post by:
Hello all,
I hope you can help me. I have developed an ".NET" application and
started to deploy the application. However, I am haveing a problem,
where when I compile the program on my laptop,...
|
by: Steve |
last post by:
I have some general catch clauses in my app as follows:
try
{
}
catch(Exception ex)
{
}
try
|
by: dmoran21 |
last post by:
I am a mathematician trying to write a program in C to do some curve
fitting. When I get to the point where I attempt to enter data in my
arrays, I get a General Protection Exception error message....
| |
by: akmkat |
last post by:
When I try to compile the following code with N = 1024, "General Protection Exception" occurs, but wehn N < 20, there is no problem. I need N = 1024, what'll I do? Plz help anyone
#include...
|
by: KhoaNguyen |
last post by:
Hi,
When i compiled these two source files, it gives me an error saying: Inaccesssible Due to its protection level.
------------Base Class-----------------
using System;
using...
|
by: manhquynh8x |
last post by:
I am programming a data compession program. It is used to compress a text file. After run program, i see this message:
Exception 13: General protection fault at o1A7..
The compiler is Turbo C++...
|
by: subhasree |
last post by:
Hi,
I am a student of mathematics and quite new to programming in C. I am trying to write a code to construct an array which at every step has to compare the value of the current element with all...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |