Files
JargonFile/original/html/M/magic-number.html
2014-03-27 18:54:56 +00:00

34 lines
4.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>magic number</title><link rel="stylesheet" href="../../jargon.css" type="text/css"/><meta name="generator" content="DocBook XSL Stylesheets V1.61.0"/><link rel="home" href="../index.html" title="The Jargon File"/><link rel="up" href="../M.html" title="M"/><link rel="previous" href="magic-cookie.html" title="magic cookie"/><link rel="next" href="magic-smoke.html" title="magic smoke"/></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">magic number</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="magic-cookie.html">Prev</a> </td><th width="60%" align="center">M</th><td width="20%" align="right"> <a accesskey="n" href="magic-smoke.html">Next</a></td></tr></table><hr/></div><dt><a id="magic-number"/><dt xmlns="" id="magic-number"><b>magic number</b>: <span xmlns="http://www.w3.org/1999/xhtml" class="grammar">n.</span></dt></dt><dd><p> [Unix/C; common] </p></dd><dd><p> 1. In source code, some non-obvious constant whose value is
significant to the operation of a program and that is inserted
inconspicuously in-line (<a href="../H/hardcoded.html"><i class="glossterm">hardcoded</i></a>), rather than
expanded in by a symbol set by a commented <b class="command">#define</b>. Magic numbers in this sense are bad style.
</p></dd><dd><p> 2. A number that encodes critical information used in an algorithm
in some opaque way. The classic examples of these are the numbers used in
hash or CRC functions, or the coefficients in a linear congruential
generator for pseudo-random numbers. This sense actually predates and was
ancestral to the more common sense</p></dd><dd><p> 3. Special data located at the beginning of a binary data file to
indicate its type to a utility. Under Unix, the system and various
applications programs (especially the linker) distinguish between types of
executable file by looking for a magic number. Once upon a time, these
magic numbers were <a href="../P/PDP-11.html"><i class="glossterm">PDP-11</i></a> branch instructions that
skipped over header data to the start of executable code; 0407, for
example, was octal for &#8216;branch 16 bytes relative&#8217;. Many other
kinds of files now have magic numbers somewhere; some magic numbers are, in
fact, strings, like the <tt class="literal">!&lt;arch&gt;</tt> at the beginning
of a Unix archive file or the <tt class="literal">%!</tt> leading PostScript
files. Nowadays only a <a href="../W/wizard.html"><i class="glossterm">wizard</i></a> knows the spells to
create magic numbers. How do you choose a fresh magic number of your own?
Simple &#8212; you pick one at random. See? It's magic! </p></dd><dd><p> 4. An input that leads to a computational boundary condition, where
algorithm behavior becomes discontinuous. Numeric overflows (particularly
with signed data types) and run-time errors (divide by zero, stack
overflows) are indications of magic numbers. The Y2K scare was probably
the most notorious magic number non-incident.</p></dd><dd><p><span class="emphasis"><em>The</em></span> magic number, on the other hand, is
<tt class="literal">7±2</tt>. See <i class="citetitle">The magical
number seven, plus or minus two: some limits on our capacity for processing
information</i> by George Miller, in the <i class="citetitle">Psychological
Review</i> 63:81-97 (1956). This classic paper established the
number of distinct items (such as numeric digits) that humans can hold in
short-term memory. Among other things, this strongly influenced the
interface design of the phone system.</p></dd><div class="navfooter"><hr/><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="magic-cookie.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="../M.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="magic-smoke.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">magic cookie </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> magic smoke</td></tr></table></div></body></html>