Skip to main content

Questions tagged [undefined-behavior]

Some languages specify "undefined behavior" for code or actions outside of the specified bounds of the language, which enables certain optimizations. Use this tag for questions about specifying undefined behaviour in a language, or optimizations relating to implementing languages with this behavior. Do not use only for undefined behavior encountered during implementation.

Filter by
Sorted by
Tagged with
10 votes
4 answers
3k views

By mathematical definition, for every nonnegative integer n and every positive integer d, it holds that the modulo ...
Dannyu NDos's user avatar
  • 1,485
7 votes
2 answers
849 views

This question is about the expected semantics when combining resource management with branching control flow. From my perspective, it applies equally to all finally-...
feldentm's user avatar
  • 2,508
1 vote
1 answer
320 views

There are high order function on lists, such as map, find, reduce, in some languages. If the result of one such function is piped into another such function, there are multiple possible evaluation ...
user23013's user avatar
  • 3,314
12 votes
4 answers
557 views

In a language like C, many functions and operators have some preconditions to work. Violating a precondition is undefined behavior. For example, when indexing an array the index must be less than the ...
mousetail's user avatar
  • 9,657
16 votes
3 answers
846 views

This is the first breaking change that C made, which was making realloc(ptr, 0) have UB instead of being roughly equivalent to ...
user1345541's user avatar
3 votes
2 answers
732 views

Many programming languages, including C89, specify that the behavior of a program in terms of sequentially executed steps, whose behavior is in turn defined in terms of the program's state when the ...
supercat's user avatar
  • 2,330
13 votes
3 answers
794 views

In my answer to another question, What was the purpose of Tartan's "disable" statement?, I asserted that it's anachronistic to use our modern C-derived definition of "undefined ...
Glenn Willen's user avatar
14 votes
3 answers
2k views

The Tartan language, designed during the process that eventually led to Ada, has a disable statement defined as follows: A disable declaration in an inner block ...
Solal Pirelli's user avatar
18 votes
3 answers
3k views

This question is tangentially related to: Why is type reinterpretation considered highly problematic in many programming languages? Regardless how 'problematic' type reinterpretation is, why do some ...
CPlus's user avatar
  • 10.5k
23 votes
10 answers
7k views

In C, accessing any indeterminate/uninitialized memory is undefined behavior, period. Even in the case that the type in question is guaranteed to have no trap representations, such as ...
CPlus's user avatar
  • 10.5k
6 votes
4 answers
1k views

Most interpreters (including those for bytecode-based languages like Java) are assumed to be exempt of UB at the low-level. For instance, I would never expect NodeJS or the Hotspot JVM to allow ...
anon's user avatar
  • 380
23 votes
4 answers
5k views

Some language specifications invite compilers to make certain assumptions, and behave in completely arbitrary fashion if such functions are violated, even if the code in question would have ...
supercat's user avatar
  • 2,330
18 votes
8 answers
7k views

In C there is a concept of trap representations, or non-value representations. If such a value is produced or used, immediate undefined behavior is invoked. This is one of the dangers of using ...
CPlus's user avatar
  • 10.5k
21 votes
6 answers
3k views

Consider the following C# snippet: Object bad= null; Console.WriteLine(bad.ToString()); This is valid C#. It will raise a ...
Robert Columbia's user avatar
5 votes
1 answer
847 views

In C currently, pointers just are, and there are no qualifiers to tell programmers whether they can be null or not. Objective-C kind of solves this problem by adding ...
CPlus's user avatar
  • 10.5k

15 30 50 per page