FACTOID # 75: Two-thirds of the world's executions occur in China.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Magic number (programming)

In computer programming, the term magic number has multiple meanings. It could refer to: Programming redirects here. ...

  • a constant used to identify a file format or protocol;
  • an unnamed and/or ill-documented numerical constant; or
  • distinctive debug values or GUIDs, et cetera.

Contents

Format indicator

Magic number origin

The type of magic number was initially found in early Seventh Edition source code of the Unix operating system and, although it has lost its original meaning, the term magic number has become part of computer industry lexicon. Seventh Edition Unix, also called Version 7 Unix, Version 7 or just V7, was an important early release of the Unix operating system. ... Filiation of Unix and Unix-like systems Unix (officially trademarked as UNIX®, sometimes also written as or ® with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy. ...


When Unix was ported to one of the first DEC PDP-11/20s it did not have memory protection and, therefore, early versions of Unix used the relocatable memory reference model.[1] Thus, pre-Sixth Edition Unix versions read an executable file into memory and jumped to the first low memory address of the program, relative address zero. With the development of paged versions of Unix, a header was created to describe the executable image components. Also, a branch instruction was inserted as the first word of the header to skip the header and start the program. In this way a program could be run in the older relocatable memory reference (regular) mode or in paged mode. As more executable formats were developed, new constants were added by incrementing the branch offset.[2] Filiation of Unix and Unix-like systems Unix (officially trademarked as UNIX®, sometimes also written as or ® with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy. ... The DEC logo Digital Equipment Corporation was a pioneering American company in the computer industry. ... The PDP-11 was a 16-bit minicomputer sold by Digital Equipment Corp. ... Memory protection is a system that prevents one process from corrupting the memory of another process running on the same computer at the same time. ... In computing, position independent code (PIC) is object code that can execute at different locations in memory. ... Sixth Edition Unix (also known as V6 Unix) was the first version of Unix to see wide release outside Bell Labs. ... A 16×16 cm area core memory plane of 128×128 bits, i. ... In computer science, an offset within an array or other data structure object is an integer indicating the distance (displacement) from the beginning of the object up until a given element or point, presumably within the same object. ... Alternate meanings: See paging (telecommunications). ... In information technology, Header refers to supplemental data placed at the beginning of a block of data being stored or transmitted, which contain information for the handling of the data block. ... An executable or executable file, in computer science, is a file whose contents are meant to be interpreted as a program by a computer. ...


In the Sixth Edition source code of the Unix program manager, the exec() service read the executable (binary) image from the file system. The first 8 bytes of the file was a header containing the sizes of the program (text) and initialized (global) data areas. Also, the first 16-bit word of the header was compared to two constants to determine if the executable image contained relocatable memory references (normal), the newly implemented paged read-only executable image, or the separated instruction and data paged image.[3] There was no mention of the dual role of the header constant, but the high order byte of the constant was, in fact, the operation code for the PDP-11 branch instruction (000407 or 0x0107). Adding seven to the program counter showed that if this constant was executed, it would branch the Unix exec() service over the executable image eight byte header and start the program. Sixth Edition Unix (also known as V6 Unix) was the first version of Unix to see wide release outside Bell Labs. ... Lions Commentary on UNIX 6th Edition, with Source Code by John Lions (1976) contains the complete source code of the 6th Edition Unix kernel plus a commentary. ... The binary numeral system, or base-2 number system, is a numeral system that represents numeric values using two symbols, usually 0 and 1. ... In computer science a byte (pronounced bite) is a unit of measurement of information storage, most often consisting of eight bits. ... In information technology, Header refers to supplemental data placed at the beginning of a block of data being stored or transmitted, which contain information for the handling of the data block. ... In mathematics and the mathematical sciences, a constant is a fixed, but possibly unspecified, value. ... An executable or executable file, in computer science, is a file whose contents are meant to be interpreted as a program by a computer. ... In computing, position independent code (PIC) is object code that can execute at different locations in memory. ... Alternate meanings: See paging (telecommunications). ... This does not cite its references or sources. ... The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. ... In mathematics and computer science, hexadecimal, base-16, or simply hex, is a numeral system with a radix, or base, of 16, usually written using the symbols 0–9 and A–F, or a–f. ...


Since the Sixth and Seventh Editions of Unix employed paging code, the dual role of the header constant was hidden. That is, the exec() service read the executable file header (meta) data into a kernel space buffer, but read the executable image into user space, thereby not using the constant's branching feature. Magic number creation was implemented in the Unix linker and loader and magic number branching was probably still used in the suite of stand-alone diagnostic programs that came with the Sixth and Seventh Editions. Thus, the header constant did provide an illusion and met the criteria for magic. This article or section does not cite its references or sources. ... In computer engineering the kernel is the core of an operating system. ... An operating system usually segregates the available system memory into kernel space and user space. ... Figure of the linking process, where object files and static libraries are assembled into a new library or executable. ... In computing, a loader is a program that performs the functions of a linker program and then immediately schedules the resulting executable program for action (in the form of a memory image), without necessarily saving the program as an executable file. ... Stand-alone is a loosely defined term used to sort computer programs. ... // A diagnostic program is a program written for the express purpose of examining the state, or locating problems with the hardware, or operating system environment that it is running on/in. ... “Illusionist” redirects here. ...


In Version Seven Unix, the header constant was not tested directly, but assigned to a variable labeled ux_mag[4] and subsequently referred to as the magic number. Given that there were approximately 10,000 lines of code and many constants employed in these early Unix versions, this indeed was a curious name for a constant, almost as curious as the You are not expected to understand this.[1] comment used in the context switching section of the Version Six program manager. Probably because of its uniqueness, the term magic number came to mean executable format type, then expanded to mean file system type, and expanded again to mean any strongly typed file. In computing, strongly-typed, when applied to a programming language, is used to describe how the language handles datatypes. ...


Magic numbers in files

Magic numbers are common in programs across many operating systems. Magic numbers implement strongly typed data and are a form of in-band signaling to the controlling program that reads the data type(s) at program run-time. Many files have such constants that identify the contained data. Detecting such constants in files is a simple and effective way of distinguishing between many file formats and can yield further run-time information. A file format is a particular way to encode information for storage in a computer file. ... Image File history File links Broom_icon. ... In computing, strongly-typed, when applied to a programming language, is used to describe how the language handles datatypes. ... It has been suggested that this article or section be merged with In-band signalling. ... A file format is a particular way to encode information for storage in a computer file. ... The ASCII codes for the word Wikipedia represented in binary, the numeral system most commonly used for encoding computer information. ...


Some examples:

  • Compiled Java class files (bytecode) start with 0xCAFEBABE.
  • GIF image files have the ASCII code for 'GIF89a' (0x474946383961) or 'GIF87a' (0x474946383761)
  • JPEG image files begin with 0xFFD8 and end with 0xFFD9. JPEG/JFIF files contain the ASCII code for 'JFIF' (0x4A464946) as a null terminated string. JPEG/Exif files contain the ASCII code for 'Exif' (0x45786966) also as a null terminated string, followed by more metadata about the file.
  • PNG image files begin with an 8-byte signature which identifies the file as a PNG file and allows immediate detection of common file transfer problems (the signature contains various newline characters for detection of unwarranted automated newline conversion, for example, if the file is transferred over FTP with the "ASCII" transfer mode instead of the "binary" mode): 211 P N G r n 032 n (0x89504e470d0a1a0a)
  • Standard MIDI music files have the ASCII code for 'MThd' (0x4D546864) followed by more metadata about the file.
  • Unix script files usually start with a shebang, '#!' (0x2321) followed by the path to an interpreter.
  • PostScript files and programs start with '%!' (0x2521).
  • PDF files start with '%PDF'.
  • Old MS-DOS .exe files and the newer Microsoft Windows PE (Portable Executable) .exe files start with the ASCII string 'MZ' (0x4D5A), the initials of the designer of the file format, Mark Zbikowski. The definition allows 'ZM' as well but it is quite uncommon.
  • The Berkeley Fast File System superblock format is identified as either 0x19540119 or 0x011954 depending on version; both represent the birthday of author Marshall Kirk McKusick.
  • Executables for the Game Boy and Game Boy Advance handheld video game systems have a 48-byte or 156-byte magic number, respectively, at a fixed spot in the header. This magic number encodes a bitmap of the Nintendo logo.
  • Zip files begin with 'PK', the initials of Phil Katz, author of DOS compression utility PKZIP.
  • Old Fat binaries (containing code for both 68K processors and PowerPC processors) on Classic Mac OS contained the ASCII code for 'Joy!' (0x4A6F7921) as a prefix.
  • TIFF files begin with either "II" or "MM" depending on the byte order (II for Intel, or little endian, MM for Motorola, or big endian), followed by 0x2A00 or 0x002A (decimal 42 as a 2-byte integer in Intel or Motorola byte ordering).
  • Unicode text files encoded in UTF-16 often start with the Byte Order Mark to detect endianness (0xFEFF for big endian and 0xFFFE for little endian). UTF-8 text files often start with the UTF-8 encoding of the same character, 0xEFBBBF.

The Unix utility program file can read and interpret magic numbers from files, and indeed, the file which is used to parse the information is called magic. The Windows utility TrID has a similar purpose. It has been suggested that this article or section be merged with Compile (software company). ... “Java language” redirects here. ... Bytecode is a binary representation of an executable program designed to be executed by a virtual machine rather than by dedicated hardware. ... GIF (Graphics Interchange Format) is a bitmap image format that is widely used on the World Wide Web, both for still images and for animations. ... Image:ASCII fullsvg There are 95 printable ASCII characters, numbered 32 to 126. ... JPG redirects here. ... A photo of a flower compressed with successively higher compression ratios from left to right. ... Image:ASCII fullsvg There are 95 printable ASCII characters, numbered 32 to 126. ... Exchangeable image file format (Exif) is a specification for the image file format used by digital cameras. ... Image:ASCII fullsvg There are 95 printable ASCII characters, numbered 32 to 126. ... Metadata is data about data. ... PNG (Portable Network Graphics), sometimes pronounced as ping, is a relatively new bitmap image format that is becoming popular on the World Wide Web and elsewhere. ... In computer science a byte (pronounced bite) is a unit of measurement of information storage, most often consisting of eight bits. ... In computing, a newline is a special character or sequence of characters signifying the end of a line of text. ... This article is about the File Transfer Protocol standardised by the IETF. For other file transfer protocols, see File transfer protocol (disambiguation). ... This article is about the File Transfer Protocol standardised by the IETF. For other file transfer protocols, see File transfer protocol (disambiguation). ... Musical Instrument Digital Interface, or MIDI, is a system designed to transmit information between electronic musical instruments. ... Image:ASCII fullsvg There are 95 printable ASCII characters, numbered 32 to 126. ... In computing, a shebang is a specific pair of characters used in a special line that begins a text file (commonly called a script) causing Unix-like operating systems to execute the commands in the text file using a specified interpreter (program) when executed. ... For the literary term, see Postscript. ... PDF is an abbreviation with several meanings: Portable Document Format Post-doctoral fellowship Probability density function There also is an electronic design automation company named PDF Solutions. ... Microsofts disk operating system, MS-DOS, was Microsofts implementation of DOS, which was the first popular operating system for the IBM PC, and until recently, was widely used on the PC compatible platform. ... “Windows” redirects here. ... The Portable Executable (PE) format is a file format for executables, object code, and DLLs, used in 32-bit and 64-bit versions of Windows operating systems. ... Image:ASCII fullsvg There are 95 printable ASCII characters, numbered 32 to 126. ... Mark Zbikowski aka Mark J. Zbikowski aka Zibo is a Microsoft Senior Software Designer. ... In computing, the Berkeley Fast File System (or FFS) is a file system used mostly by BSD-derivative Unix variants. ... Marshall Kirk McKusick (b. ... For the entire Game Boy series of handheld consoles, see Game Boy line. ... “GBA” redirects here. ... Nintendo Company, Limited (任天堂 or ニンテンドー Nintendō; NASDAQ: NTDOY, TYO: 7974 usually referred to as simply Nintendo, or Big N ) is a multinational corporation founded on September 23, 1889[1] in Kyoto, Japan by Fusajiro Yamauchi to produce handmade hanafuda cards. ... The ZIP file format is a popular data compression and archival format. ... Phil Katz, shown in 1994, holds a computer disk containing compression software made by his company, PKWare Inc. ... This article is about the family of closely related operating systems for the IBM PC compatible platform. ... PKZIP is an archiving tool originally written by the late Phil Katz, and marketed by his company PKWARE, Inc. ... A fat binary (or multiarchitecture binary) is a computer program that is native to multiple instruction set architectures (ISA) and thus can be run on multiple processor types. ... The Motorola 680x0/0x0/m68k/68k/68K family of CISC microprocessor CPU chips were 32-bit from the start, and were the primary competition for the Intel x86 family of chips in personal computers of the 1980s and early 1990s. ... PowerPC is a RISC microprocessor architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM. Originally intended for personal computers, PowerPC CPUs have since become popular embedded and high-performance processors as well. ... This article relates to both the original Classic Mac OS as well as Mac OS X, Apples more recent operating system. ... Image:ASCII fullsvg There are 95 printable ASCII characters, numbered 32 to 126. ... This article is about TIFF, the computer image format. ... The Ultimate Answer to Life, The Universe, and Everything The 42 Puzzle, as it appeared in The Illustrated Hitchhikers Guide to the Galaxy The Answer to Life, the Universe, and Everything has a numeric solution in Douglas Adams series The Hitchhikers Guide to the Galaxy. ... The Unicode Standard, Version 5. ... In computing, UTF-16 is a 16-bit Unicode Transformation Format, a character encoding form that provides a way to represent a series of abstract characters from Unicode and ISO/IEC 10646 as a series of 16-bit words suitable for storage or transmission via data networks. ... A Byte Order Mark (BOM) is the character at code point U+FEFF (zero-width no-break space), when that character is used to denote the endianness of a string of UCS/Unicode characters encoded in UTF-16 or UTF-32 and/or as a marker to indicate that text... In computing, endianness is the byte (and sometimes bit) ordering in memory used to represent some kind of data. ... UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. ... file is a program originated in Unix that runs under the shell (command-line) to determine the file type heuristically instead of other simpler ways to classify it, like with file extensions, MIMEs, etc. ... TrID is a utility designed to identify file types from their binary signatures. ...


Magic numbers in protocols

  • The OSCAR protocol, used in AIM/ICQ, prefixes requests with 0x2A.
  • In the RFB protocol used by VNC, a client starts its conversation with a server by sending "RFB" (0x524642, for "Remote Frame Buffer") followed by the client's protocol version number.
  • In the SMB protocol used by Microsoft Windows, each SMB request or server reply begins with 0xff534d42, or "ÿSMB" at the start of the SMB request.
  • In the MSRPC protocol used by Microsoft Windows, each TCP-based request begins with 0x05 at the start of the request (representing Microsoft DCE/RPC Version 5), followed immediately by a 0x00 or 0x01 for the minor version. In UDP-based MSRPC requests the first byte is always 0x04.
  • DCOM object instantiation requests carried over MSRPC have a huge container object called ORPC This. This contains smaller object reference structures, called OBJREFs, which are always prefixed with the byte sequence "MEOW". Debugging extensions (used for DCOM channel hooking) are prefaced with the byte sequence "MARB".
  • Unencrypted Bittorrent tracker requests begin with a single byte, 0x13 representing the header length, followed immediately by the phrase "BitTorrent protocol" at byte position 1.
  • eDonkey/eMule traffic begins with a single byte representing the client version. Currently 0xe3 represents an eDonkey client, 0xc5 represents eMule,and 0xd4 represents compressed eMule.
  • SSL transactions always begin with a "client hello" message. The record encapsulation scheme used to prefix all SSL packets consists of two- and three- byte header forms. Typically an SSL version 2 client hello message is prefixed with a 0x80 and SSLv3 server response to a client hello begins with 0x16 (though this may vary).
  • DHCP packets use a "magic cookie" value of 0x63825363 at the start of the options section of the packet. This value is included in all DHCP packet types.

Image File history File links This is a lossless scalable vector image. ... OSCAR is AOLs instant messaging and presence information protocol standing for Open System for CommunicAtion in Realtime. ... AIM is a three-letter abbreviation with multiple meanings, as described below: AOL Instant Messenger A I M Management Group Inc. ... ICQ is an instant messaging computer program, owned by Time Warners AOL subsidiary. ... RFB (“remote framebuffer”) is a simple protocol for remote access to graphical user interfaces. ... Virtual Network Computing (VNC) is a desktop sharing system which uses the RFB (Remote FrameBuffer) protocol to remotely control another computer. ... The initialism SMB may stand for: San Miguel Beer, a local beer in the Philippines. ... MSRPC (Microsoft Remote Procedure Call) is a modified version of DCE/RPC. Additions include support for Unicode strings, implicit handles, inheritance of interfaces (which are extensively used in DCOM), and complex calculations in the variable-length string and structure paradigms already present in DCE/RPC. The DCE 1. ... DCOM (Distributed Component Object Model) is a Microsoft proprietary technology for software components distributed across several networked computers. ... MSRPC (Microsoft Remote Procedure Call) is a modified version of DCE/RPC. Additions include support for Unicode strings, implicit handles, inheritance of interfaces (which are extensively used in DCOM), and complex calculations in the variable-length string and structure paradigms already present in DCE/RPC. The DCE 1. ... This article is about the protocol. ... eDonkey may refer to: eDonkey network / eDonkey2000 network - popular file sharing network used by millions of people. ... eMule is a peer-to-peer file sharing application for Microsoft Windows. ... ASIM can refer to: In computing and electronics: Secure Sockets Layer, a communications protocol, predecessor to Transport Layer Security Server-Side Language, a category of programming languages used on the web which execute on the server S/SL programming language Single Stuck Line, a fault model for digital circuits In... DHCP in the context of computing can stand for: Dynamic Host Configuration Protocol - one of the protocols in the TCP/IP networking suite Decentralized Hospital Computer Program of the United States Department of Veterans Affairs This article consisting of a 4-letter acronym or initialism is a disambiguation page — a...

Unnamed numerical constant

The term magic number also refers to the bad programming practice of using numbers directly in source code without explanation. In most cases this makes programs harder to read, understand, and maintain. Although most guides make an exception for the numbers zero and one, it is a good idea to define all other numbers in code as named constants. In computer science and mathematics, a variable (IPA pronunciation: ) (sometimes called a pronumeral) is a symbolic representation denoting a quantity or expression. ...


For example, to shuffle the values in an array randomly, this pseudocode will do the job: Pseudocode (derived from pseudo and code) is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of programming languages, but omits detailed subroutines, variable declarations or language-specific syntax. ...

 for i from 1 to 52 j := i + randomInt(53 - i) - 1 a.swapEntries(i, j) 

where a is an array object, the function randomInt(x) chooses a random integer between 1 to x, inclusive, and swapEntries(i, j) swaps the ith and jth entries in the array. In this example, 52 is a magic number. It is considered better programming style to write:

 constant int deckSize := 52 for i from 1 to deckSize j := i + randomInt(deckSize + 1 - i) - 1 a.swapEntries(i, j) 

This is preferable for several reasons:

  • It is easier to read and understand. A programmer reading the first example might wonder, What does the number 52 mean here? Why 52? The programmer might infer the meaning after reading the code carefully, but it's not obvious. Magic numbers become particularly confusing when the same number is used for different purposes in one section of code.
  • It is easier to alter the value of the number, as it is not redundantly duplicated. Changing the value of a magic number is error-prone, because the same value is often used several times in different places within a program. Also, if two semantically distinct variables or numbers have the same value they may be accidentally both edited together. To modify the first example to shuffle a Tarot deck, which has 78 cards, a programmer might naively replace every instance of 52 in the program with 78. This would cause two problems. First, it would miss the value 53 on the second line of the example, which would cause the algorithm to fail in a subtle way. Second, it would likely replace the characters 52 everywhere, regardless of whether they refer to the deck size or to something else entirely, which could introduce bugs. By contrast, changing the value of the deckSize variable in the second example would be a simple, one-line change.
  • The declarations of "magic number" variables are placed together, usually at the top of a function or file, facilitating their review and change.
  • It facilitates parameterization. For example, to generalize the above example into a procedure that shuffles a deck of any number of cards, it would be sufficient to turn deckSize into a parameter of that procedure. The first example would require several changes, perhaps:
 function shuffle (int deckSize) for i from 1 to deckSize j := i + randomInt(deckSize + 1 - i) - 1 a.swapEntries(i, j) 
  • It helps detect typos. Using a variable (instead of a literal) takes advantage of a compiler's checking (if any). Accidentally typing "62" instead of "52" would go undetected, whereas typing "dekSize" instead of "deckSize" would result in the compiler's warning that dekSize is undeclared.
  • It can reduce typing in some IDEs. If an IDE supports code completion, it will fill in most of the variable's name from the first few letters.
  • Although a naive programmer might assume that the expression "53" was quicker for the CPU to process than the expression "deckSize + 1", most modern compilers and interpreters are capable of using the fact that the variable "deckSize" has been declared as a constant and pre-calculate the value 53 in the code that is eventually executed. There is therefore usually no speed advantage to using magic numbers in code.

Disadvantages are: This article is about the general history, iconography, and uses of tarot cards. ... A typographical error or typo is a mistake made during the typing process. ... An integrated development environment (IDE), also known as integrated design environment and integrated debugging environment, is a programming environment that has been packaged as an application program,that assists computer programmers in developing software. ... Autocomplete is a feature provided by many source code text editors, word processors, and web browsers. ...

  • It can increase the line length of the source code, forcing lines to be broken up if many constants are used on the same line.
  • It can make debugging more difficult, especially on systems where the debugger doesn't display the values of constants.

Allowed use of magic numbers

In some contexts the use of unnamed numerical constants is permissible. While these contexts are subjective, and often depend on individual coding habits, the following are common examples where unnamed constants are permissible:

  • the use of 0 and 1 while indexing through an array
  • the use of 10 as a multiplier or divisor when dealing with decimal (base-10) numbers (especially when performing modulus operations to access the lowest-order digit)
  • the use of 2 as a multiplier or divisor when an algorithm requires doubling or halving of a value
  • the use of 2 as a divisor when checking if a number is even or odd (any even number modulo 2 gives 0, and any odd number modulo 2 gives 1)
  • the use of hexadecimal values 0x80 and 0x01 as masks to access the highest- and lowest-order bits in a byte

The use of the constants 0 and 1 are sometimes used to represent the boolean values True and False in some programming languages (such as C and C++). The C standard library includes macro definitions for TRUE (1) and FALSE (0), and the use of these constants is generally encouraged. The word modulo (Latin, with respect to a modulus of ___) is the Latin ablative of modulus which itself means a small measure. ... C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ... C++ (pronounced see plus plus, IPA: ) is a general-purpose programming language with high-level and low-level capabilities. ...


Likewise 0 is sometimes used to represent the null pointer or reference. As with boolean values, the C standard library includes a macro definition NULL whose use is encouraged when dealing with null pointers.


Problems with magic numbers

Because magic numbers are of an arbitrary value, they do not often carry a meaning by themselves; in most cases it is up to the documentation of one's code to specify exactly what the magic number represents. Also, magic numbers are not typesafe, that is, one could erroneously add one to another and arrive at a nonsensical result. Lastly, although highly coincidental, situations arise when numbers may accidentally match magic numbers during comparison operations. It is for these reasons that the use of Enumerated types, or enums, is quickly overtaking the use of magic numbers. Although enums are represented in most languages as a glorified integer (a notable exception is Java)[5], the name of the enum is used rather than the number itself, facilitating programming. In computer programming, an enumerated type is an abstract data type used to model an attribute that has a specific number of options (or identifiers) such as the suit of a playing card (i. ... “Java language” redirects here. ...


Magic GUIDs

Although highly discouraged, some programmers use GUIDs that hold some human-understandable meaning. This is discouraged since it might compromise the uniqueness of the ID. A Globally Unique Identifier or GUID is a pseudo-random number used in software applications. ... A Globally Unique Identifier or GUID is a pseudo-random number used in software applications. ...


Magic debug values

Magic debug values are specific values written to memory during allocation or deallocation, so that it will later be possible to tell whether or not they have become corrupted, and to make it obvious when values taken from uninitialized memory are being used. RAM redirects here. ... It has been suggested that this article or section be merged with Dynamic memory allocation. ...


Since it is unlikely that any given 32-bit integer would take this specific value, the appearance of such a number in a debugger or memory dump can indicate common errors such as buffer overflows, or uninitialized variables. A debugger is a computer program that is used to test and debug other programs. ... A core dump is an unstructured record of the contents of working memory at a specific time, generally used to debug a program that has terminated abnormally (crashed). ...


Memory is usually viewed in hexadecimal, so common values used are often repeated digits or hexspeak. Hexspeak, like leetspeak, is a novelty form of variant English spelling. ...


Famous and common examples include:

  • 0x..FACADE : Used by a number of RTOSes
  • 0xA5A5A5A5 : Used in embedded development because the alternating bit pattern (10100101) creates an easily recognized pattern on oscilloscopes and logic analyzers.
  • 0xABABABAB : Used by Microsoft's HeapAlloc() to mark "no man's land" guard bytes after allocated heap memory
  • 0xABADBABE : Used by Apple as the "Boot Zero Block" magic number
  • 0xABADCAFE : A startup to this value to initialize all free memory to catch errant pointers
  • 0xBAADF00D : Used by Microsoft's LocalAlloc(LMEM_FIXED) to mark uninitialised allocated heap memory
  • 0xBADBADBADBAD : Burroughs large systems "uninitialized" memory (48-bit words)
  • 0xBADCAB1E : Error Code returned to the Microsoft eVC debugger when connection is severed to the debuggee
  • 0xBADC0FFEE0DDF00D : Used on IBM RS/6000 64-bit systems to indicate uninitialized CPU registers
  • 0xBADDCAFE : On Sun Microsystems' Solaris, marks uninitialised kernel memory (KMEM_UNINITIALIZED_PATTERN)
  • 0xBEEFCACE : Used by Microsoft .NET as a magic number in resource files
  • 0xC0DEDBAD : A memory leak tracking tool which it will change the MMU tables so that all references to address zero
  • 0xCAFEBABE : Used by both Mach-O ("Fat binary" in both 68k and PowerPC) to identify object files and the Java programming language to identify .class files
  • 0xCAFEFEED : Used by Sun Microsystems' Solaris debugging kernel to mark kmemfree() memory
  • 0xCEFAEDFE : Seen in Intel Mach-O binaries on Apple Computer's Mac OS X platform (see 0xFEEDFACE below)
  • 0xCCCCCCCC : Used by Microsoft's C++ debugging runtime library to mark uninitialised stack memory
  • 0xCDCDCDCD : Used by Microsoft's C++ debugging runtime library to mark uninitialised heap memory
  • 0xDDDDDDDD : Used by MicroQuill's SmartHeap and Microsoft's C++ debugging heap to mark freed heap memory
  • 0xDEADBABE : Used at the start of Silicon Graphics' IRIX arena files
  • 0xDEADBEEF : Famously used on IBM systems such as the RS/6000, also used in the original Mac OS operating systems, OPENSTEP Enterprise, and the Commodore Amiga. On Sun Microsystems' Solaris, marks freed kernel memory (KMEM_FREE_PATTERN)
  • 0xDEADDEAD : A Microsoft Windows STOP Error code used when the user manually initiates the crash.
  • 0xDEADF00D : All the newly allocated memory which is not explicitly cleared when it is munged
  • 0xEBEBEBEB : From MicroQuill's SmartHeap
  • 0xFADEDEAD : Comes at the end to identify every OSA script
  • 0xFDFDFDFD : Used by Microsoft's C++ debugging heap to mark "no man's land" guard bytes before and after allocated heap memory
  • 0xFEEDBABEF00D : A home-brewed Ethernet address
  • 0xFEEDFACE : Seen in PowerPC Mach-O binaries on Apple Computer's Mac OS X platform. On Sun Microsystems' Solaris, marks the red zone (KMEM_REDZONE_PATTERN)
  • 0xFEEEFEEE : Used by Microsoft's HeapFree() to mark freed heap memory
  • 0xFEE1DEAD : Used by Linux reboot() syscall

Note that most of these are each 32 bits long — the word size of most modern computers. A real-time operating system (RTOS) is a multitasking operating system intended for real-time applications. ... Illustration showing the interior of a cathode-ray tube for use in an oscilloscope. ... A logic analyzer displays signals in a digital circuit that are too fast to be observed by a human being and presents it to a user so that the user can more easily check correct operation of the digital system. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... Please wikify (format) this article as suggested in the Guide to layout and the Manual of Style. ... Apple Inc. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... The Burroughs large systems were the largest of three series of Burroughs Corporation mainframe computers. ... For other uses, see IBM (disambiguation) and Big Blue. ... The IBM pSeries, formerly called RS/6000 (for RISC System/6000), is IBMs current RISC/UNIX-based workstation and server computer line. ... Sun Microsystems, Inc. ... Solaris is a computer operating system developed by Sun Microsystems. ... Mach-O, short for Mach object file format, is a file format for executables and object code. ... A fat binary (or multiarchitecture binary) is a computer program that is native to multiple instruction set architectures (ISA) and thus can be run on multiple processor types. ... “Java language” redirects here. ... Sun Microsystems, Inc. ... Solaris is a computer operating system developed by Sun Microsystems. ... Mach-O, short for Mach object file format, is a file format for executables and object code. ... Apple Inc. ... Mac OS X (IPA: ) is a line of graphical operating systems developed, marketed, and sold by Apple Inc. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... To meet Wikipedias quality standards, this article or section may require cleanup. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... Silicon Graphics, Inc. ... IRIX is a computer operating system developed by Silicon Graphics, Inc. ... For other uses, see IBM (disambiguation) and Big Blue. ... The IBM pSeries, formerly called RS/6000 (for RISC System/6000), is IBMs current RISC/UNIX-based workstation and server computer line. ... This article relates to both the original Classic Mac OS as well as Mac OS X, Apples more recent operating system. ... An operating system (OS) is the software that manages the sharing of the resources of a computer and provides programmers with an interface used to access those resources. ... OpenStep is an open object-oriented API specification for an object-oriented operating system that uses any modern operating system as its core, principly developed by NeXT. It is important to recognize that while OpenStep is an API specification, OPENSTEP (all capitalized) is a specific implementation of this OpenStep developed... Commodore, the commonly used name for Commodore International, was an American electronics company based in West Chester, Pennsylvania which was a vital player in the home/personal computer field in the 1980s. ... This article is about the family of home computers. ... Sun Microsystems, Inc. ... Solaris is a computer operating system developed by Sun Microsystems. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... Please wikify (format) this article as suggested in the Guide to layout and the Manual of Style. ... Mach-O, short for Mach object file format, is a file format for executables and object code. ... Apple Inc. ... Mac OS X (IPA: ) is a line of graphical operating systems developed, marketed, and sold by Apple Inc. ... Sun Microsystems, Inc. ... Solaris is a computer operating system developed by Sun Microsystems. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... This article is about operating systems that use the Linux kernel. ... This article is about the unit of information. ... In computer hardware terminology, word size (word length) is the number of bits that a CPU can process at one time (the word). ...


The prevalence of these values in Microsoft technology is no coincidence; they are discussed in detail in Steve Maguire's well-known book Writing Solid Code from Microsoft Press. He gives a variety of criteria for these values, such as:

  • They should not be useful; that is, most algorithms that operate on them should be expected to do something unusual. Numbers like zero don't fit this criterion.
  • They should be easily recognized by the programmer as invalid values in the debugger.
  • On machines that don't have byte alignment, they should be odd numbers, so that dereferencing them as addresses causes an exception.
  • They should cause an exception, or perhaps even a debugger break, if executed as code.

Since they were often used to mark areas of memory that were essentially empty, some of these terms came to be used in phrases meaning "gone, aborted, flushed from memory"; e.g. "Your program is DEADBEEF". The introduction to this article provides insufficient context for those unfamiliar with the subject matter. ... In mathematics, any integer (whole number) is either even or odd. ...


Pietr Brandehörst's ZUG programming language initialized memory to either 0x0000, 0xDEAD or 0xFFFF in development environment and to 0x0000 in the live environment, on the basis that uninitialised variables should be encouraged to misbehave under development to trap them, but encouraged to behave in a live environment to reduce errors.


See also

A file format is a particular way to encode information for storage in a computer file. ... A file format is a particular way to encode information for storage in a computer file. ... In computing, NaN (Not a Number) is a value or symbol that is usually produced as the result of an operation on invalid input operands, especially in floating-point calculations. ... In computer programming, an enumerated type is an abstract data type used to model an attribute that has a specific number of options (or identifiers) such as the suit of a playing card (i. ...

References

  1. ^ a b Odd Comments and Strange Doings in Unix[1]
  2. ^ Personal communication with Dennis M. Ritchie
  3. ^ Version six system1 source file[2]
  4. ^ Version seven system1 source file[3]
  5. ^ Java 5.0 Programming Guide, "Enums" http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

  Results from FactBites:
 
Magic number (programming) - Wikipedia, the free encyclopedia (1446 words)
Magic numbers become particularly confusing when the same number is used for different purposes in one section of code.
The declarations of "magic number" variables are placed together, usually at the top of a function or file, facilitating their review and change.
Magic debug values are specific values written to memory during allocation or deallocation, so that it will later be possible to tell whether or not they have become corrupted and to make it obvious when values taken from uninitialized memory are being used.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.