Sujet : Re: More Funny Stuff From Joel
De : bowman (at) *nospam* montana.com (rbowman)
Groupes : comp.os.linux.advocacyDate : 14. Jun 2024, 00:16:24
Autres entêtes
Message-ID : <ld19dnFa6idU1@mid.individual.net>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Pan/0.149 (Bellevue; 4c157ba)
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? For that matter what
are the initial values of md_count[0] through md_count[8] ?
I used memset(&md_count, 0, sizeof md_count); with the original
declaration or you could have used calloc().
Same difference. You wind up with something that's not an array of
whatever random crap is on the stack.
- add return 0
picky, picky... I suppose you want 'int main(void)' too. I can't remember
the guy's name but he was a prolific author of programming books in the
early '80s whose examples always started with 'void main(). If comments
in programming forums could kill he would have had an early retirement.
Not for nothing but in VS Code if you don't initialize 'mode' at the point
where it's used there is a red squiggle that pops up 'identifier "mode" is
undefinedC/C++(20)' It doesn't flag an uninitialized 'mean', although
'mean += nums[len];' assumes it was 0.0. Points to clang for that one.