Skip to main content
28 votes

What optimizations does the strict aliasing rule facilitate?

The main thing the optimizer wants to know here is whether writes through one pointer might affect reads through other pointers or names. When it knows for sure that two pointers are unrelated in this ...
rpjohnst's user avatar
  • 814
25 votes

What are the pitfalls of indirect implicit casting?

Type checking is dramatically less effective The main goal of type checking is to notice bugs before they happen, and to present them explicitly as bugs instead of causing the program to continue ...
Rydwolf Programs's user avatar
24 votes

Why is type reinterpretation considered highly problematic in many programming languages?

It forces a well defined interpretation of all types involved In order to have a well-defined reinterpretation of a cast between two types, their exact binary representations must always be well ...
mousetail's user avatar
  • 8,339
19 votes
Accepted

What are the pitfalls of indirect implicit casting?

Ambiguity and its Consequences One immediate downside is that the chain of casts may be ambiguous. For example, suppose that we have types A–...
Wheelwright's user avatar
14 votes

Why is type reinterpretation considered highly problematic in many programming languages?

Because it is problematic. Its a dangerous thing to do. Errors in code that does it can be devilishly hard to track down. Perhaps an illustration will help. I once had some code in K&R C that was ...
T.E.D.'s user avatar
  • 249
10 votes

Why is type reinterpretation considered highly problematic in many programming languages?

Non-Portability Particularly with pointers and floating-point numbers, there was a lot of hardware out there where even loading an invalid value into certain registers would cause a CPU fault and ...
Davislor's user avatar
  • 1,062
8 votes

What optimizations does the strict aliasing rule facilitate?

Aliasing As mentioned by @rpjohnst's answer, the definite absence of aliasing is the optimization enabler. That is, a number of optimizations are only sound -- ie, do not alter the semantics -- if the ...
Matthieu M.'s user avatar
  • 3,039
6 votes

What optimizations does the strict aliasing rule facilitate?

The issue is discussed explicitly in the C99 Rationale at https://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf starting on page 59, line 33, and continuing through the top of line 61. ...
supercat's user avatar
  • 1,812
6 votes
Accepted

Pros and cons of user-defined implicit casting

This is a trade-off between making the language convenient to write in vs. making it easier to avoid bugs caused by using the feature incorrectly or unintentionally (i.e. not creating footguns). Most ...
kaya3's user avatar
  • 19.7k
5 votes

Why is type reinterpretation considered highly problematic in many programming languages?

Managed Pointers Casting a managed Object to an unmanaged byte* could lead to the object getting deallocated while you're ...
Bbrk24's user avatar
  • 9,057
3 votes

Why is type reinterpretation considered highly problematic in many programming languages?

While casting the pointers to these types is often allowed, casting the values usually isn't. I guess the reason is that the cast has unknown arbitrary cost and requires code. My research project ...
feldentm's user avatar
  • 1,779
3 votes
Accepted

Implementing a number to string semantics efficiently in a C-style language?

Some languages have direct syntactic means to achieve this: let x = 10; let str = "x: \(x)" However that syntax does not allow one to specify radix or ...
Bbrk24's user avatar
  • 9,057
3 votes

Pros and cons of user-defined implicit casting

Uniformity Many languages have some sorts of implicit casts built-in. Derived to base class is one example, but there's also bool coercion, integer widening, boxing,...
abel1502's user avatar
  • 2,517
3 votes

What are the pitfalls of indirect implicit casting?

TL;DR: Don't offer implicit casts at all (besides trivial, reliable ones that you define in your language specification, e.g. casts from int8 to ...
Ralf Kleberhoff's user avatar
3 votes
Accepted

Why is type-punning at compile-time a no-go?

Disclaimer: Unfortunately, due to C being an ISO standard, the exact reason(s) may only have briefly existed orally within the room where the committee met, and we are most likely stuck with (educated)...
Matthieu M.'s user avatar
  • 3,039
2 votes
Accepted

Determining the most optimized data type for the platform with type inference

Test suit If you plan to compile to LLVM IR, then you can write a small set of programs in LLVM IR to determine what variations of encoding/representation of data are fast for some common operations. ...
André L F S Bacci's user avatar
2 votes

Pros and cons of user-defined implicit casting

What is User-Defined Casting? What does that mean at all? It's a way to call some user-defined method, getting one input parameter and returning some different result. If we call this method a "...
Ralf Kleberhoff's user avatar
2 votes

What are the pitfalls of indirect implicit casting?

Frame challenge: The question assumes that implicit casting is okay. The biggest problem I see with supporting indirect implicit casting is that you are supporting implicit casting. Don't do it, every ...
Questor's user avatar
  • 181
1 vote

Pros and cons of user-defined implicit casting

Pro: Upgraded types shares the same simple values Say the language itself supports only basic integers, and libraries has implemented high precision integers, rationals, complex numbers (of integers), ...
user23013's user avatar
  • 2,510

Only top scored, non community-wiki answers of a minimum length are eligible