Re: Malloc code



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
.



Relevant Pages

  • Re: Detached Process crash with unknown exit status 7B0017C0
    ... David J Dachtera mentioned in passing: ... >> file and run the process via that command file? ... which I assume you need) and attached to DEBUG. ... DBS freeware http://www.users.bigpond.com/dbsneddon/software.htm ...
    (comp.os.vms)
  • Re: HEADS UP: /bin and /sbin are now dynamically linked
    ... David O'Brien wrote: ... lets agree that the FTP client will be ... > the last thing added to /rescue that is outside the original charter. ... > URL to the bits I need, and if so with fetch you're still screwed. ...
    (freebsd-current)
  • Re: Malloc code
    ... It's clearer than before, as David says, and it isn't immediately obvious why you should see junk. ... But the code although prettier than before is still pretty horrible - BAD_POINTER is set if an allocation fails but left unassigned if it succeeds; and you take no notice if the malloc fails - you just dereference the pointer anyway. ...
    (microsoft.public.vc.language)
  • Re: Is your old ONdigi. box locking up today?
    ... > David wrote: ... >>>Your valued genuine mail to them might just get erased as it's not ... >>>spotted amongst the other junk. ...
    (uk.tech.digital-tv)
  • Re: fc5 hangs
    ... David L wrote: ... telinit 3 by itself didn't help. ... debug this? ... I've been using redhat/fedora for ~11 years now, ...
    (Fedora)

Loading