tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: Thomas Auer <tom () cosy ! sbg ! ac ! at>
To: tru64-unix-managers
Subject: SUMMARY: Problems with malloc()
Date: Thu, 14 Dec 1995 18:08:40 +0000	[thread overview]
Message-ID: <96075325906651.tru64-unix-managers.marc@archive.invalid> (raw)

Last week I wrote:

>I have a problem with a small c program. The following instruction
>returns a pointer to (void *) 0x140024800
>32        if ((allocMem = (void *) calloc(nrOfElems,size)) == NULL)
>33        {
>34          printf("ERROR ALLOCATING MEMORY\n");
>35          exit(1);
>36        }
>
>but later, on, I try to access th 88th element of my array, which is 
>located at 
>
>(gdb) print curElem
>$3 = (t_point *) 0x14002a000
>
>(gdb) print *curElem
>Cannot access memory at address 0x14002a000.
>
>which is exactly the address of the 88th element, and since the malloc did 
>not return NULL, I assume that the allocation worked. 

Unfortunately this was NOT mthe correct address. Next morning I found that
I had forgotten about c-pointer arithmetics. Half past 2 in the morning isn't
exactly the best time to search for errors in my code. I found my mistake 
within 5 minutes the next morning. Please apologize that I have bothered you.

Sometimes I feel really stupid. :-(

Special thanks to all of you who tried to help me!

merry christmas to all of you,
tom
-- 
* Thomas Auer         | Think where man's glory most begins and ends. *
* tom@cosy.sbg.ac.at  |    And say my glory was I had such friends.   *
*  Univ. of Salzburg, |                          William Butler Yeats *
*       AUSTRIA       | http://www.cosy.sbg.ac.at/~tom/tom.html       *

                 reply	other threads:[~1995-12-14 18:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox