34 lines
4.3 KiB
HTML
34 lines
4.3 KiB
HTML
|
|
<?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><EFBFBD></td><th width="60%" align="center">M</th><td width="20%" align="right"><EFBFBD><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 ‘branch 16 bytes relative’. Many other
|
|||
|
|
kinds of files now have magic numbers somewhere; some magic numbers are, in
|
|||
|
|
fact, strings, like the <tt class="literal">!<arch></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 — 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<EFBFBD>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><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="../M.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="magic-smoke.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">magic cookie<69></td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>magic smoke</td></tr></table></div></body></html>
|