Sujet : Re: More Funny Stuff From Joel
De : bowman (at) *nospam* montana.com (rbowman)
Groupes : comp.os.linux.advocacyDate : 14. Jun 2024, 18:46:40
Autres entêtes
Message-ID : <ld3affFja99U1@mid.individual.net>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Pan/0.149 (Bellevue; 4c157ba)
On Fri, 14 Jun 2024 09:45:29 -0400, DFS wrote:
On 6/13/2024 6:16 PM, rbowman wrote:
On Thu, 13 Jun 2024 15:08:50 -0400, DFS wrote:
- malloc the md_count[] array to size 9 (because there
are only 9 unique values in the size 10 dataset)
What memory location is md_count[9]++ incrementing?
9 is the correct size for md_count[], but then you have to play games
with index addressing and looping.
So malloc() to size 10 and life's good.
Right. Did you play games with the index when you malloc'd 9?
For that matter what are the initial values of md_count[0] through
md_count[8] ?
0.
man malloc
The malloc() function allocates size bytes and returns a pointer to the
allocated memory. The memory is not initialized. If size is 0, then
malloc() returns either NULL, or a unique pointer value that can
later be successfully passed to free().
'The memory is not initialized.' is underlined on the man page. Some days
you get lucky.