Deutsch   English   Français   Italiano  
<87y1796bfn.fsf@nosuchdomain.example.com>

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: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: "undefined behavior"?
Date: Wed, 12 Jun 2024 15:30:52 -0700
Organization: None to speak of
Lines: 56
Message-ID: <87y1796bfn.fsf@nosuchdomain.example.com>
References: <666a095a$0$952$882e4bbb@reader.netnews.com>
	<8t3k6j5ikf5mvimvksv2t91gbt11ljdfgb@4ax.com>
	<666a18de$0$958$882e4bbb@reader.netnews.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 13 Jun 2024 00:30:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="32c0f168ad8ff54df06981ba253a92e6";
	logging-data="1935800"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/jMtGZKigGaNBGP/UVjCnt"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:nw9fkPLIJRX1ipIKVXuvgLRyrwU=
	sha1:YErO+7MdFET652FxrUGnTAynvDk=
Bytes: 3255

DFS <nospam@dfs.com> writes:
> On 6/12/2024 5:30 PM, Barry Schwarz wrote:
>> On Wed, 12 Jun 2024 16:47:23 -0400, DFS <nospam@dfs.com> 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?

>>> Also, why doesn't gcc just do you a solid and initialize to "" for you?
>> Makes perfect sense.  The first rule of undefined behavior is
>> "Whatever happens is exactly correct."  You are not entitled to any
>> expectations and none of the behavior (or perhaps all of the behavior)
>> can be called unexpected.
>
> I HATE bogus answers like this.
>
> Aren't you embarrassed to say things like that?

He has nothing to be embarrassed about.  What he wrote is correct.

The C standard's definition of "undefined behavior" is "behavior, upon
use of a nonportable or erroneous program construct or of erroneous
data, for which this International Standard imposes no requirements".

If you don't like the way C deals with undefined behavior, that's
perfectly valid, and a lot of people are likely to agree with you.
But I advise against lashing out at people who are correctly explaining
what the C standard says.

DFS, since you've been posting in comp.lang.c for at least ten years,
I'm surprised you're having difficulties with this.

[...]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */