Jump to content

Null (computer programming): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
rv: Invented terminology, discussion of unrelated topics, confusing, verbose
rv What invented terminology... I've been a computer professional since '76... see WP:NOT PAPERS... verbosity needed in tech subjects
Line 1: Line 1:
'''Null''' has several meanings in [[computer programming]].
The word '''Null''' has several meanings in [[computer programming]], but one way or another all of them refer to operations on data [[stream (computer science)|streams]] or data values, or attributes of parades of ([[array<!-- (computing)-->]]) the data of type "characters" such as length.
{{Left66|88|BG=1|P=1em;|M=1em auto 1em auto; float:center; align:center;}}In order to aid understanding, it should be understood that many [[data type]]s are abstractions, and the actual implementation depends on [[microprocessor|machine dependent]], characteristics such as binary word lengths. So to do the various national or international standards for exchanging or representing text related data such as [[unicode]] or [[ASCII]] as are referenced below, save those standards are written with explicit instructions on code values for a particular length of computer word&mdash;hence data values, when discussed at all below are given as abstractions, not values. In an particular physical (non-abstract) implementation, the two are married, giving users a working computing system that can talk and be understood via those same information interchange standards with other computers.</div>

{{Anchors|Null pointer|Null reference|Null Pointer|Null Reference}}
;Null pointer or null reference
;Null pointer or null reference
* Null is a special [[pointer]] value (or other kind of object [[reference (computer science)|reference]]) used to signify that a pointer intentionally does not point to (or refer to) an object. Such a pointer is called a [[Pointer#The null pointer|null pointer]].<ref>[[Brian W. Kernighan]], [[Dennis M. Ritchie]], ''[[The C Programming Language]]'', Second Edition, Prentice Hall New Jersey, ISBN 0-13-110362-8, p. 102</ref> Many implementations use a value of 0 (all bits zero) to represent the null pointer, as this is at the bottom of the address space of most [[CPU]]s (although some architectures use a signed address space and use the most negative value). Many [[operating system]]s generate an exception when an attempt is made to access this memory address. Some languages use other nomenclature for such a pointer, e.g., [[Pascal (language)|Pascal]] and [[Ruby (language)|Ruby]] use <code>nil</code><ref>[[Elliot B. Koffman]], ''Pascal 3rd Edition'', Addison Wesley, Reading MA, ISBN 0-201-11834-3, pp. 678-679</ref>, while [[Visual Basic]] uses <code>Nothing</code>. [[Fortran]] does not consider it a constant, but a property that can be set by the NULLIFY directive and tested by the ASSOCIATED function.
* Null is a special [[pointer]] value (or other kind of object [[reference (computer science)|reference]]) used to signify that a pointer intentionally does not point to (or refer to) an object. Such a pointer is called a [[Pointer#The null pointer|null pointer]].<ref>[[Brian W. Kernighan]], [[Dennis M. Ritchie]], ''[[The C Programming Language]]'', Second Edition, Prentice Hall New Jersey, ISBN 0-13-110362-8, p. 102</ref> Many implementations use a value of 0 (all bits zero) to represent the null pointer, as this is at the bottom of the address space of most [[CPU]]s (although some architectures use a signed address space and use the most negative value). Many [[operating system]]s generate an exception when an attempt is made to access this memory address. Some languages use other nomenclature for such a pointer, e.g., [[Pascal (language)|Pascal]] and [[Ruby (language)|Ruby]] use <code>nil</code><ref>[[Elliot B. Koffman]], ''Pascal 3rd Edition'', Addison Wesley, Reading MA, ISBN 0-201-11834-3, pp. 678-679</ref>, while [[Visual Basic]] uses <code>Nothing</code>. [[Fortran]] does not consider it a constant, but a property that can be set by the NULLIFY directive and tested by the ASSOCIATED function.


{{Anchors|Null value|Null Value}}
;Null value
;Null value
* In many disciplines, the concept of [[null]] allows a [[Many-valued logic|three-valued logic]], with null indicating "no value" or an "unknown value". The [[SQL]] database query language uses Null in this way, as do [[Visual Basic]] and its derivatives. In this model, an expression that depends on the value of a Null operand will evaluate to Null (VB) or "unknown" (SQL). So, for any A, the expressions "A = Null" and "A <> Null" are neither true nor false. However, the boolean operation "A and False" produces false, and similarly "A or True" is true, even when A is Null, because these expressions do not depend on the value of A. (Some SQL implementations may consider A = Null to be "true" if A is Null; see [[Null (SQL)]]).
* In many disciplines, the concept of [[null]] allows a [[Many-valued logic|three-valued logic]], with null indicating "no value" or an "unknown value". The [[SQL]] database query language uses Null in this way, as do [[Visual Basic]] and its derivatives. In this model, an expression that depends on the value of a Null operand will evaluate to Null (VB) or "unknown" (SQL). So, for any A, the expressions "A = Null" and "A <> Null" are neither true nor false. However, the boolean operation "A and False" produces false, and similarly "A or True" is true, even when A is Null, because these expressions do not depend on the value of A. (Some SQL implementations may consider A = Null to be "true" if A is Null; see [[Null (SQL)]]).


{{Anchor|Null character|Null Character}}
;[[Null character]]
* In the [[C0 and C1 control codes|C0]] control code set defined in the [[ISO/IEC 646|ISO 646]], [[ASCII]], and [[Unicode]] character set standards, a character data type having the code set's ''value of 0 ([[zero])'' is the [[null character]] (NUL). Most [[programming languages]] provide syntax for representing this character as a literal value (e.g., [[Pascal programming language|Pascal]] uses chr(0) or #0, [[C (programming language)|C]] and its many derivatives use '\0'). <ref> Kernighan and Ritchie, ''C'', p. 38 </ref>

{{Anchors|Null String|Null string}}
;Null string
;Null string
* A [[String (computer science)|string]] in all computer languages is an array of characters, normally implemented as the shortest discrete data type the machine can address. A '''null string''', also known as an [[empty string]], is a string (array) of zero contents, which is to say of zero length or to phrase it differently, one that holds zero characters. In the C, language, a zero length string is expressly referred to as a Null string<ref> Kernighan and Ritchie, ''C'', p. 38 </ref> by Kernighan and Ritchie, but in context, C uses pointers to index into a string, so the null string of C is not a {{here|null pointer}} (for that is defined), but a string data location, the first character of an array, containing the {{here|null character}} '\x00' (or '\0', a [[zero]] value&mdash;). A properly initialized pointer, pointing to a null character value in C is using two memory locations of two different data types, and the fact that the [[lvalue]] of that location is zero is C's definition and test for a null string (See {{here|ASCIZ}} below, and the next paragraph about languages which store string lengths). <br
* A null [[String (computer science)|string]], also known as an [[empty string]], is a string of zero length. <ref> Kernighan and Ritchie, ''C'', p. 38 </ref>
/><br
/>Depending upon the computing language, current code environment, and other contextual factors a null string may or may not take up significant memory space. A dynamically allocated string (local within a function or sub-program is usually allocated space on the stack frame, its maximum (allocated) length making up part of the overall length of the stack frame. A static variable, with no contents is however allocated N-bytes of memory at the time of compiling and linking, which is part of the binary space the computer addresses when that program is loaded. Both have zero meaningful contents until and unless they are initialized by valid data, and most compilers are written to initialize dynamically allocated character arrays as null strings until they are initialized. In C, that means the first byte or word of the ASCIZ string would be set to zero. Other languages, notably various BASIC programming implementations use the first byte or machine data word of the character array to hold the length of the string. Testing for nullness there means testing for a zero value meaning the string has zero length. (Testing on a "random number", would be the result if this were not the case, which could then cause a program branch to the wrong code handling the results of the hypothetical test.)


;Null device
;Null device
Line 15: Line 24:
* In '''Windows XP''', null device is a file in system32/drivers, named Null.sys, the size is 2944 bytes. It can be seen in device manager, non-plug-and-play group.
* In '''Windows XP''', null device is a file in system32/drivers, named Null.sys, the size is 2944 bytes. It can be seen in device manager, non-plug-and-play group.


{{Anchor|ASCIZ}}
;[[Null character]]
* In the [[C0 and C1 control codes|C0]] control code set defined in the [[ISO/IEC 646|ISO 646]], [[ASCII]], and [[Unicode]] character set standards, code value 0 is the [[null character]] (NUL). Most [[programming languages]] provide syntax for representing this character as a literal value (e.g., [[Pascal programming language|Pascal]] uses chr(0) or #0, [[C (programming language)|C]] and its many derivatives use '\0'). <ref> Kernighan and Ritchie, ''C'', p. 38 </ref>

* In some [[programming languages]], the null character denotes the end of a character [[string (computer science)|string]]. Such strings that are encoded with the [[ASCII]] character set are sometimes referred to as ''[[C string|ASCIIZ]]'' or ''ASCIZ'' strings &mdash; the "Z" indicating that the string ends with a "Zero", or null character<ref>Kernighan and Ritchie, ''C'', p. 30 </ref>.
* In some [[programming languages]], the null character denotes the end of a character [[string (computer science)|string]]. Such strings that are encoded with the [[ASCII]] character set are sometimes referred to as ''[[C string|ASCIIZ]]'' or ''ASCIZ'' strings &mdash; the "Z" indicating that the string ends with a "Zero", or null character<ref>Kernighan and Ritchie, ''C'', p. 30 </ref>.
* When electromechanical [[teleprinter]]s were used as computer output devices, one or more null characters were sent at the end of each printed line to allow time for the mechanism to return to the first printing position on the next line.
* When electromechanical [[teleprinter]]s were used as computer output devices, one or more null characters were sent at the end of each printed line to allow time for the mechanism to return to the first printing position on the next line.

Revision as of 21:36, 16 July 2008

The word Null has several meanings in computer programming, but one way or another all of them refer to operations on data streams or data values, or attributes of parades of (array) the data of type "characters" such as length.

Template:Left66In order to aid understanding, it should be understood that many data types are abstractions, and the actual implementation depends on machine dependent, characteristics such as binary word lengths. So to do the various national or international standards for exchanging or representing text related data such as unicode or ASCII as are referenced below, save those standards are written with explicit instructions on code values for a particular length of computer word—hence data values, when discussed at all below are given as abstractions, not values. In an particular physical (non-abstract) implementation, the two are married, giving users a working computing system that can talk and be understood via those same information interchange standards with other computers.

Null pointer or null reference
  • Null is a special pointer value (or other kind of object reference) used to signify that a pointer intentionally does not point to (or refer to) an object. Such a pointer is called a null pointer.[1] Many implementations use a value of 0 (all bits zero) to represent the null pointer, as this is at the bottom of the address space of most CPUs (although some architectures use a signed address space and use the most negative value). Many operating systems generate an exception when an attempt is made to access this memory address. Some languages use other nomenclature for such a pointer, e.g., Pascal and Ruby use nil[2], while Visual Basic uses Nothing. Fortran does not consider it a constant, but a property that can be set by the NULLIFY directive and tested by the ASSOCIATED function.

Null value
  • In many disciplines, the concept of null allows a three-valued logic, with null indicating "no value" or an "unknown value". The SQL database query language uses Null in this way, as do Visual Basic and its derivatives. In this model, an expression that depends on the value of a Null operand will evaluate to Null (VB) or "unknown" (SQL). So, for any A, the expressions "A = Null" and "A <> Null" are neither true nor false. However, the boolean operation "A and False" produces false, and similarly "A or True" is true, even when A is Null, because these expressions do not depend on the value of A. (Some SQL implementations may consider A = Null to be "true" if A is Null; see Null (SQL)).

Null character
  • In the C0 control code set defined in the ISO 646, ASCII, and Unicode character set standards, a character data type having the code set's value of 0 ([[zero]) is the null character (NUL). Most programming languages provide syntax for representing this character as a literal value (e.g., Pascal uses chr(0) or #0, C and its many derivatives use '\0'). [3]

Null string
  • A string in all computer languages is an array of characters, normally implemented as the shortest discrete data type the machine can address. A null string, also known as an empty string, is a string (array) of zero contents, which is to say of zero length or to phrase it differently, one that holds zero characters. In the C, language, a zero length string is expressly referred to as a Null string[4] by Kernighan and Ritchie, but in context, C uses pointers to index into a string, so the null string of C is not a Template:Here (for that is defined), but a string data location, the first character of an array, containing the Template:Here '\x00' (or '\0', a zero value—). A properly initialized pointer, pointing to a null character value in C is using two memory locations of two different data types, and the fact that the lvalue of that location is zero is C's definition and test for a null string (See Template:Here below, and the next paragraph about languages which store string lengths).

    Depending upon the computing language, current code environment, and other contextual factors a null string may or may not take up significant memory space. A dynamically allocated string (local within a function or sub-program is usually allocated space on the stack frame, its maximum (allocated) length making up part of the overall length of the stack frame. A static variable, with no contents is however allocated N-bytes of memory at the time of compiling and linking, which is part of the binary space the computer addresses when that program is loaded. Both have zero meaningful contents until and unless they are initialized by valid data, and most compilers are written to initialize dynamically allocated character arrays as null strings until they are initialized. In C, that means the first byte or word of the ASCIZ string would be set to zero. Other languages, notably various BASIC programming implementations use the first byte or machine data word of the character array to hold the length of the string. Testing for nullness there means testing for a zero value meaning the string has zero length. (Testing on a "random number", would be the result if this were not the case, which could then cause a program branch to the wrong code handling the results of the hypothetical test.)
Null device
  • In UNIX systems, /dev/null (also referred to as the black hole or bit bucket) is a special file that delivers no input when read from and discards all output when written to. The NUL device has similar functionality in DOS and Windows. On AmigaOS it is known as the NIL: device.
  • In Windows XP, null device is a file in system32/drivers, named Null.sys, the size is 2944 bytes. It can be seen in device manager, non-plug-and-play group.

  • In some programming languages, the null character denotes the end of a character string. Such strings that are encoded with the ASCII character set are sometimes referred to as ASCIIZ or ASCIZ strings — the "Z" indicating that the string ends with a "Zero", or null character[5].
  • When electromechanical teleprinters were used as computer output devices, one or more null characters were sent at the end of each printed line to allow time for the mechanism to return to the first printing position on the next line.
Null variant
  • Some programming languages (such as LISP; Ruby; and Pascal, Delphi, and other languages based on Pascal) use nil for the null variant, which can sometimes lead to confusing errors if null is accidentally used instead of nil.
Null script / null subroutine
Null Account
  • On certain forums and other internet sites, user database corruption might cause user accounts to suddenly show up as "null" and have all their settings reset. Generally this will remove the user's ability to add new content to the site.

References

  1. ^ Brian W. Kernighan, Dennis M. Ritchie, The C Programming Language, Second Edition, Prentice Hall New Jersey, ISBN 0-13-110362-8, p. 102
  2. ^ Elliot B. Koffman, Pascal 3rd Edition, Addison Wesley, Reading MA, ISBN 0-201-11834-3, pp. 678-679
  3. ^ Kernighan and Ritchie, C, p. 38
  4. ^ Kernighan and Ritchie, C, p. 38
  5. ^ Kernighan and Ritchie, C, p. 30