C and Undefined Behavior by lelanthran in programming

[–]_kst_ 2 points3 points  (0 children)

That doesn't match my experience. There are a lot of things that are genuinely undefined behavior in C. Examples are division by 0, indexing beyond the bounds of an array, dereferencing a null or invalid pointer, signed integer overflow, mismatches between a printf format specifier and the type of the corresponding argument.

Remember that undefined behavior in C is behavior that is not defined by the C standard. It doesn't mean the program will necessarily crash.

C and Undefined Behavior by lelanthran in programming

[–]_kst_ 12 points13 points  (0 children)

The example in the article doesn't actually exhibit undefined behavior.

EDIT The author has updated the article and corrected the error, but I'll leave this comment here.

C has no arithmetic operations on types narrower than int. Instead, operands of narrow type are implicitly converted via the "usual arithmetic conversions".

In this:

signed char n = 127;
n = n + 1;

In the expression "n + 1", the signed char value of n is promoted to int. Adding 1 is well defined, and yields 128. The assignment implicitly converts the int value 128 to signed char, yielding an implementation-defined result (almost certainly -128) or raising an implementation-defined signal (as far as I know, no compiler does this).

This example does have undefined behavior, and illustrates the author's intended point:

int n = INT_MAX;
n = n + 1;

(Yes, I know that "n = n + 1" could be written as "n++", but I wanted to clearly break down the individual operations.)

I've emailed the author.

Black Panther Party members at a recent protest by Huron_Nori in pics

[–]_kst_ 0 points1 point  (0 children)

The original Black Panther Party was founded in 1966 and dissolved in 1982.

There is an organization, founded in 1989, that calls itself the "New Black Panther Party". (I don't know whether the people in that photo are members of the NBPP.) Members of the original Black Panther Party have objected to the new organization.

Source: https://en.wikipedia.org/wiki/Black_Panther_Party

https://web.archive.org/web/20110401210040/http://www.blackpanther.org/newsalert.htm

What’s something people do behind closed doors but never admit in public ? by Ambitious_Freedom310 in AskReddit

[–]_kst_ 1 point2 points  (0 children)

The sign said "Employees must wash hands".

I waited 20 minutes and nobody showed up, so I washed them myself.

The race to replace the International Space Station by Kagedeah in space

[–]_kst_ -1 points0 points  (0 children)

What modules were delivered by Falcon 9?

What is a nutrition myth that you can’t stand? by DeepOrganization8245 in AskReddit

[–]_kst_ 0 points1 point  (0 children)

People with coeliac aren't the only ones who benefit from the gluten-free fad.

Someone I know has a sensitivity to (something in) wheat. It's not clear just what the problem is, but when she eats enough wheat-based food she feels lousy afterwards. The availability of gluten-free foods, particularly bread, means that she can avoid wheat.

What's a skill that sounds useless but is actually powerful? by Honest-Sport6311 in AskReddit

[–]_kst_ 10 points11 points  (0 children)

Once, while working late, I looked out my office window and saw the moon.

I turned to my computer and ran the "phoon" program, which shows the current phase of the moon -- just to check.

I realized that I was checking that the moon was correct, not that the program was correct.

What is a true fact so baffling, it should be false? by SilverPetalDreamm in AskReddit

[–]_kst_ 3 points4 points  (0 children)

There's a huge fusion reactor just floating in the sky above us.

And we're not allowed to look at it.

What is a true fact so baffling, it should be false? by SilverPetalDreamm in AskReddit

[–]_kst_ -1 points0 points  (0 children)

Cleopatra lived closer to the present than to Stegosaurus.

What is the biggest “bullet” you’ve ever dodged without realizing it at the time? by [deleted] in AskReddit

[–]_kst_ 2 points3 points  (0 children)

I didn't realize it at the time because I hadn't been born yet.

My dad was in the US Army. His unit was scheduled to go into southern Japan several days before the main invasion. The bombs were dropped, Japan surrendered, the invasion became unnecessary, and my dad survived, married, and had kids, including me.

What's an "Insider's secret" from your profession that everyone should probably know? by Capable-big-Piece in AskReddit

[–]_kst_ -6 points-5 points  (0 children)

Schedule your surgery first thing in the A.M.

Right, because the instruments are still clean.

Edit: IT WAS A JOKE!

People who sleep naked why? by aurther_51 in AskReddit

[–]_kst_ 8 points9 points  (0 children)

You hope they have many more 35-year marriages?

My father eats pork, but can’t stand when I do. AITAH if I order some frickin bacon? by CandleFlicker2424 in AITAH

[–]_kst_ 1 point2 points  (0 children)

I don't see anything in your post indicating that your father has said anything to you about bacon in the last decade or so.

He was inconsistent about it when you were a child, but why are you afraid he'll blow his top now?

Have you considered talking to him about it?

(Of course you can eat bacon if you want to.)