![]() |
|
#1
|
|||
|
|||
An Access Violation Segmentation FaultHello,
i everyone, i made some code to simulate the working of a shade motor and but it dosent work because an error appear which states An Access Violation Segmentation Fault raised in your program, i dont know what to do, perhaps you guys can figure that out. CPP / C++ / C Code:
Thanks for your time and help. Best Regards, Boschow. Last edited by LuciWiz : 02-Feb-2008 at 14:52.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: An Access Violation Segmentation Fault[quote=boschow]i made some code.../QUOTE]
That code won't compile because you had commented out the declaration for MM. If you had left the declaration uncommented, then the effect would have been the following: 1. You declare MM to be a pointer to a struct of type MainModule. 2. You don't give the pointer a value, so its value is something arbitrary. I don't know what the value is, but one thing for sure: the pointer is not guaranteed to be pointing to any memory that your program can use. 3. Then you try to store stuff into whatever memory is pointed to by the unitialized pointer. The result is "undefined behavior," and can definitely cause an access violation. Solution: Declare a variable of type MainModule. Then you can access the various memory locations within the block of memory that is defined. CPP / C++ / C Code:
Or, if you really want to use a (or need to use) a pointer: CPP / C++ / C Code:
Regards, Dave |
|
#3
|
|||
|
|||
Re: An Access Violation Segmentation FaultThanks for the info, it worked successfully. I also came across another method to use pointer this is :
Code:
but i think you solution is better. Best regards, BoSCHoW. |
|
#4
|
|||
|
|||
Re: An Access Violation Segmentation FaultQuote:
There are times when declaring a pointer and then using new to get memory for the object is "better." Unless I have a reason to do it with dynamically allocated memory, I usually just declare the object. I think it is important to understand what is happening in either case and, therefore, to be comfortable with being able to use either method as circumstances might impel. Regards, Dave |
Recent GIDBlog
I?m Home by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| segmentation fault error | vermin1302 | C Programming Language | 7 | 25-Feb-2006 14:38 |
| Another Segmentation Fault Problem | SergeDrago | C++ Forum | 2 | 30-Nov-2005 15:16 |
| Please help segmentation fault problem | robsmith | C Programming Language | 1 | 08-May-2005 21:34 |
| segmentation fault in c++ | rushman8282 | C++ Forum | 2 | 26-Jan-2005 04:38 |
| access violation | gmn | MS Visual C++ / MFC Forum | 3 | 04-Aug-2004 07:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The