Re: Malloc code
- From: David Wilkinson <no-reply@xxxxxxxxxxxx>
- Date: Sat, 29 Dec 2007 16:56:33 -0500
Robby wrote:
Hello,
David is right when he said:
They do this by writing well-structured programs which are straightforward to debug, not by writing programs which are almost impossible to debug, and being some kind of magician when they try to debug them. The result is that the magician you want is probably not available.
Which is why I have further reduced the code sample and oddly enough even with not declaring any global variables, I still get junk. David, I have nothing against whatever you have said in your previous posts. However, I am just trying to understand a little about why two mallocs declarations don't do what their supposed to do... that is allocate the right data in the right memory area. I can relate to your anger towards me. No offense taken my freind.
Anyhow, if any help out there, I would really need it! Quite discouraged!
Here is a much clearer and easier to understand piece of code.
<snip>
That's it!
The for loop in fetch(), sometimes displays junk. I am supposed to read (2,4,6,8,10,12,14,16,18,20,22,24) 11 times and thats not what I read!
And if pMCB1 is not declared global, then how do I free it when comming out of fetch(); ?
Please accept that the malloc for the pCL_B pointer must reside in fetch() as shown above.
Robby:
1. If you must top-post, please trim previous replies.
2. This code may be clearer than before, but it is full of functions that do nothing but call other functions, functions that have no external effect, and local variables that are assigned but not used. Try to go through the code and examine the purpose of each line in the context of the example. Also make sure each function has a purpose (returns information to the caller).
3. What do you mean by "sometimes displays junk"?
4. In response to your specific question, why not free the memory in main?
int main()
{
struct MCB *px;
px = (struct MCB *) TCP_CONFIG_GMM();
LCD_PAINTSCREEN(px);
free(px);
return 0;
}
5. Note that main() should return int.
--
David Wilkinson
Visual C++ MVP
.
- Follow-Ups:
- Re: Malloc code
- From: Robby
- Re: Malloc code
- References:
- Malloc code
- From: Robby
- RE: Malloc code
- From: Robby
- Malloc code
- Prev by Date: RE: Malloc code
- Next by Date: Re: Malloc code
- Previous by thread: RE: Malloc code
- Next by thread: Re: Malloc code
- Index(es):
Relevant Pages
|
Loading