Deutsch   English   Français   Italiano  
<v4ef0n$26ru6$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: "undefined behavior"?
Date: Thu, 13 Jun 2024 10:43:51 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <v4ef0n$26ru6$1@dont-email.me>
References: <666a095a$0$952$882e4bbb@reader.netnews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 13 Jun 2024 11:43:52 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="67a186d3dfa54250815f91d60b152bd4";
	logging-data="2322374"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/4c/kjOpWtJgRk68US/jDw"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:UoigNK7GwIVVKGWf+B4NaP9zTPw=
In-Reply-To: <666a095a$0$952$882e4bbb@reader.netnews.com>
Content-Language: en-GB
Bytes: 2484

On 12/06/2024 21:47, DFS wrote:
> Wrote a C program to mimic the stats shown on:
> 
> https://www.calculatorsoup.com/calculators/statistics/descriptivestatistics.php
> 
> My code compiles and works fine - every stat matches - except for one 
> anomaly: when using a dataset of consecutive numbers 1 to N, all values 
>  > 40 are flagged as outliers.  Up to 40, no problem.  Random numbers 
> dataset of any size: no problem.
> 
> And values 41+ definitely don't meet the conditions for outliers (using 
> the IQR * 1.5 rule).
> 
> Very strange.
> 
> Edit: I just noticed I didn't initialize a char:
> before: char outliers[100];
> after : char outliers[100] = "";
> 
> And the problem went away.  Reset it to before and problem came back.
> 
> Makes no sense.  What could cause the program to go FUBAR at data point 
> 41+ only when the dataset is consecutive numbers?

I assume outliers is inside a function.

What are the 100 values of outliers if you don't initialise it? You can 
try printing them out (as individual numbers not as a string) although 
just doing that, and adding that extra code, may change the actual values.

However that doesn't matter if it still goes wrong; you may still get a 
hint as to why it's behaving as it is.

> Also, why doesn't gcc just do you a solid and initialize to "" for you?

Initialising to "" will zero the entire array. You really want the 
compiler to do that work, even when you're going to overwrite it anyway?