Update
This commit is contained in:
parent
7a760cb7f7
commit
9f0e34a0dd
17 changed files with 1932 additions and 1890 deletions
|
@ -55,6 +55,7 @@ A great many commonly used tricks in programming could be regarded as hacks even
|
|||
- **[bit hacks](bit_hack.md)**: Clever manipulations of [bits](bit.md) -- for example it is possible to swap two variable without a temporary variables by using the [xor](xor.md) function. Another simplest example is implementing division by 2 as binary shift by 1 (this hack is used in real life by people for quickly dividing by 10, we just remove the last digit).
|
||||
- **[copyleft](copyleft.md)**: A legal hack by [Richard Stallman](rms.md), connected to [free software](free_software.md), working on the basis of the following idea: "If [copyright](copyright.md) lets me put any conditions on my work, I may impose a condition on my work that says that any modified version must not impose any restrictive conditions".
|
||||
- In minimalist [C](c.md) programming mainly two standards of the language are used: C89 and C99. To distinguish between them in source code one can e.g. exploit the fact that C99 introduced line comments (starting with `//`) and make such code that C99 sees part of it commented out while C89 doesn't. For example the following two lines: `int isC89 = 1 //**/ 2`, `; isC89 = !isC89;`.
|
||||
- **shades of gray on 1bit display**: There is a trick, used for example by [Arduboy](arduboy.md) developers, that allows displaying shades of gray [colors](color.md) on a display that can normally only display two colors: black and white. The trick lies in quickly blinking a pixel, which to the eye will create the illusion of black and white color averaged over time, and the blinking ratio can further created more shades of gray. The requirement here is sufficiently high FPS of course.
|
||||
- **[fast inverse square root](fast_inverse_sqrt.md)**: Famous hack that was used in the [game](game.md) Quake, it [approximates](approximation.md) an inverse of [square root](sqrt.md) of a [floating point](float.md) number by treating it as an integer and bashing it with a [magic constant](magic_constant.md), which is about four times faster than computing the value with the obvious floating point division.
|
||||
- **memory [rape](rape.md) in [C](c.md)**: E.g. instead of doing proper memory allocation with potentially inefficient and bloated `malloc` one may try to do a custom memory allocation without any libraries by abusing allocation on stack -- allocate a variable size array in main, set some global pointer to it and then manage this chunk of memory with your own allocation functions.
|
||||
- **actually portable executable** (https://justine.lol/ape.html): Justine Tunney found a way to create an executable format that passes as a valid NATIVE executable on all major systems including [GNU](gnu.md)/[Linux](linux.md), [Windows](windows.md) and [Mac](mac.md), i.e. it is possible to compile a native program (e.g. with [C](c.md)) and then have it natively run on any major OS.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue