473,490 Members | 2,486 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

General Protection Exception

6 New Member
I have encoutered a problem "General Protection Exception" when trying to run this program, I need a help on a urgent basis:

the code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define L 20
  5. #define V 30
  6. #define O 2
  7. #define N 4
  8.  
  9. struct Element
  10.  {
  11.     unsigned int c[L];
  12.     int value ;
  13.  };
  14.  
  15. struct Variable
  16.  {
  17.     struct Element e[V] ;
  18.     double y[V] ;
  19.     double f[O] ;
  20.  };
  21.  
  22. void initializeElement(struct Element*);
  23.  
  24. void main(void)
  25.  {
  26.     Variable *x ;
  27.     int i,j ;
  28.     x = (struct Variable*)malloc(sizeof(struct Variable) * N);
  29.  
  30.     for( i = 0 ; i < N ; i++ )
  31.         {
  32.           for( j = 0 ; j < V ; j++ )
  33.               {
  34.                  initializeElement(&(x[i].e[j]));
  35.                  x[i].y[j] = 0 ;
  36.                  x[i].f[j] = 0 ;
  37.               }
  38.  
  39.           for( j = 0 ; j < O ; j++ )
  40.               x[i].f[j] = 0 ;
  41.         }
  42.  }
  43.  
  44.  
  45. void initializeElement( struct Element *e)
  46.  {
  47.     int i, r ;
  48.     for( i = 0 ; i < L ; i++ )
  49.         {
  50.           r = rand() % 1000 ;
  51.           if( r < 500 )
  52.               e -> c[i] = 0 ;
  53.           else
  54.               e -> c[i] = 1 ;
  55.         }
  56.     e -> value = 0 ;
  57.  }
  58.  
Plz help anyone as soon as possible.
Mar 4 '07 #1
6 1629
AdrianH
1,251 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1.               {
  2.                  initializeElement(&(x[i].e[j]));
  3.                  x[i].y[j] = 0 ;
  4.                  x[i].f[j] = 0 ;
  5.               }
  6.  
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
Mar 4 '07 #2
DeMan
1,806 Top Contributor
You've been looking at the code too long. :-)
Ain't that the truth way too often
Mar 4 '07 #3
akmkat
6 New Member
I have encoutered a problem "General Protection Exception" when trying to run this program, I need a help on a urgent basis:

the code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define L 20
  5. #define V 30
  6. #define O 2
  7. #define N 1024
  8.  
  9. struct Element
  10.  {
  11.     unsigned int c[L];
  12.     int value ;
  13.  };
  14.  
  15. struct Variable
  16.  {
  17.     struct Element e[V] ;
  18.     double y[V] ;
  19.     double f[O] ;
  20.  };
  21.  
  22. void initializeElement(struct Element*);
  23.  
  24. void main(void)
  25.  {
  26.     Variable *x ;
  27.     int i,j ;
  28.     x = (struct Variable*)malloc(sizeof(struct Variable) * N);
  29.  
  30.     for( i = 0 ; i < N ; i++ )
  31.         {
  32.           for( j = 0 ; j < V ; j++ )
  33.               {
  34.                  initializeElement(&(x[i].e[j]));
  35.                  x[i].y[j] = 0 ;
  36.                  //x[i].f[j] = 0 ;
  37.               }
  38.  
  39.           for( j = 0 ; j < O ; j++ )
  40.               x[i].f[j] = 0 ;
  41.         }
  42.  }
  43.  
  44.  
  45. void initializeElement( struct Element *e)
  46.  {
  47.     int i, r ;
  48.     for( i = 0 ; i < L ; i++ )
  49.         {
  50.           r = rand() % 1000 ;
  51.           if( r < 500 )
  52.               e -> c[i] = 0 ;
  53.           else
  54.               e -> c[i] = 1 ;
  55.         }
  56.     e -> value = 0 ;
  57.  }
  58.  
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?
Mar 5 '07 #4
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
Mar 5 '07 #5
akmkat
6 New Member
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
Mar 5 '07 #6
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
Mar 5 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5038
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...
39
2762
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...
0
1556
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,...
3
2873
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
37
7106
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....
2
1913
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...
0
1578
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...
1
6624
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++...
2
3030
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...
0
6974
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...
0
7356
tracyyun
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...
0
5448
agi2029
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,...
1
4878
isladogs
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...
0
3084
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...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
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 ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.