Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Record (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Record type== ===Operations=== Operations for a record type include: * Declaration of a record type, including the position, type, and (possibly) name of each field * Declaration of a record; a variable typed as a record type * Construction of a record value; possibly with field value initialization * Read and write record field value * Comparison of two records for equality * Computation of a standard [[hash function|hash value]] for the record Some languages provide facilities that enumerate the fields of a record. This facility is needed to implement certain services such as [[debugging]], [[garbage collection (computing)|garbage collection]], and [[serialization]]. It requires some degree of [[type polymorphism]]. In contexts that support record subtyping, operations include adding and removing fields of a record. A specific record type implies that a specific set of fields are present, but values of that type may contain additional fields. A record with fields ''x'', ''y'', and ''z'' would thus belong to the type of records with fields ''x'' and ''y'', as would a record with fields ''x'', ''y'', and ''r''. The rationale is that passing an (''x'',''y'',''z'') record to a function that expects an (''x'',''y'') record as argument should work, since that function will find all the fields it requires within the record. Many ways of practically implementing records in programming languages would have trouble with allowing such variability, but the matter is a central characteristic of record types in more theoretical contexts. ====Assignment and comparison==== Most languages allow assignment between records that have exactly the same record type (including same field types and names, in the same order). Depending on the language, however, two record data types defined separately may be regarded as distinct types even if they have exactly the same fields. Some languages may also allow assignment between records whose fields have different names, matching each field value with the corresponding field variable by their positions within the record; so that, for example, a [[complex data type|complex number]] with fields called <code>real</code> and <code>imag</code> can be assigned to a [[Cartesian coordinates|2D point]] record variable with fields <code>X</code> and <code>Y</code>. In this alternative, the two operands are still required to have the same sequence of field types. Some languages may also require that corresponding types have the same size and encoding as well, so that the whole record can be assigned as an uninterpreted [[bit string]]. Other languages may be more flexible in this regard, and require only that each value field can be legally assigned to the corresponding variable field; so that, for example, a [[short integer]] field can be assigned to a [[long integer]] field, or vice versa. Other languages (such as [[COBOL]]) may match fields and values by their names, rather than positions. These same possibilities apply to the comparison of two record values for equality. Some languages may also allow order comparisons ('<'and '>'), using the [[lexicographic order]] based on the comparison of individual fields.{{Citation needed|date=May 2009}} [[PL/I]] allows both of the preceding types of assignment, and also allows ''structure expressions'', such as <code>a = a+1;</code> where "a" is a record, or structure in PL/I terminology. ====Algol 68's distributive field selection==== In Algol 68, if <code>Pts</code> was an array of records, each with integer fields <code>X</code> and <code>Y</code>, one could write <code>Y '''of''' Pts</code> to obtain an array of integers, consisting of the <code>Y</code> fields of all the elements of <code>Pts</code>. As a result, the statements <code>Y '''of''' Pts[3] := 7</code> and <code>(Y '''of''' Pts)[3] := 7</code> would have the same effect. ====Pascal's "with" statement==== In [[Pascal programming language|Pascal]], the command <code>with R do S</code> would execute the command sequence <code>S</code> as if all the fields of record <code>R</code> had been declared as variables. Similarly to entering a different [[namespace]] in an object-oriented language like [[C Sharp (programming language)|C#]], it is no longer necessary to use the record name as a prefix to access the fields. So, instead of writing <code>Pt.X := 5; Pt.Y := Pt.X + 3</code> one could write {{code|2=pascal|1=with Pt do begin X := 5; Y := X + 3 end}}. ===Representation in memory=== The representation of a record in memory varies depending on the programming language. Often, fields are stored in consecutive memory locations, in the same order as they are declared in the record type. This may result in two or more fields stored into the same word of memory; indeed, this feature is often used in [[systems programming]] to access specific bits of a word. On the other hand, most compilers will add padding fields, mostly invisible to the programmer, in order to comply with alignment constraints imposed by the machine—say, that a [[floating point]] field must occupy a single word. Some languages may implement a record as an array of addresses pointing to the fields (and, possibly, to their names and/or types). Objects in object-oriented languages are often implemented in rather complicated ways, especially in languages that allow [[class inheritance|multiple class inheritance]]. ===Self-defining records=== A ''self-defining record'' is a type of record which contains information to identify the record type and to locate information within the record. It may contain the offsets of elements; the elements can therefore be stored in any order or may be omitted.<ref>{{cite web |last1=Kraimer |first1=Martin R. |title=EPICS Input / Output Controller (IOC) Application Developer's Guide |url=http://www.aps.anl.gov/epics/EpicsDocumentation/AppDevManuals/AppDevGuide/3.12BookFiles/AppDevGuide.book.html |website=Argonne National Laboratory |access-date=November 25, 2015 }}</ref> The information stored in a self-defining record can be interpreted as [[metadata]] for the record, which is similar to what one would expect to find in the [[Unix|UNIX]] [[metadata]] regarding a file, containing information such as the record's creation time and the size of the record in [[byte]]s. Alternatively, various elements of the record, each including an element identifier, can simply follow one another in any order.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)