Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Pascal (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
===Pointer types=== Pascal supports the use of [[pointer (computer programming)|pointer]]s: :<syntaxhighlight lang="pascal"> type pNode = ^Node; Node = record a : integer; b : char; c : pNode end; var NodePtr : pNode; IntPtr : ^integer; </syntaxhighlight> Here the variable ''NodePtr'' is a pointer to the data type ''Node'', a record. Pointers can be used before they are declared. This is a [[forward declaration]], an exception to the rule that things must be declared before they are used. To create a new record and assign the value ''10'' and character ''A'' to the fields ''a'' and ''b'' in the record, and to initialise the pointer ''c'' to the [[null pointer]] ("NIL" in Pascal), the statements would be: :<syntaxhighlight lang="pascal"> new(NodePtr); ... NodePtr^.a := 10; NodePtr^.b := 'A'; NodePtr^.c := nil; ... </syntaxhighlight> This could also be done using the <code>with</code> statement, as follows: <syntaxhighlight lang="pascal"> new(NodePtr); ... with NodePtr^ do begin a := 10; b := 'A'; c := nil end; ... </syntaxhighlight> Inside of the scope of the ''with'' statement, a and b refer to the subfields of the record pointer ''NodePtr'' and not to the record Node or the pointer type pNode. [[Linked list]]s, [[Stack (abstract data type)|stacks]] and [[Queue (abstract data type)|queues]] can be created by including a pointer type field (c) in the record. Unlike many languages that feature pointers, Pascal only allows pointers to reference dynamically created variables that are anonymous, and does not allow them to reference standard static or local variables. Pointers also must have an associated type, and a pointer to one type is not compatible with a pointer to another type (e.g. a pointer to a char is not compatible with a pointer to an integer). This helps eliminate the type security issues inherent with other pointer implementations, particularly those used for [[PL/I]] or [[C (Programming Language)|C]]. It also removes some risks caused by [[dangling pointers]], but the ability to dynamically deallocate referenced space by using the ''dispose'' function (which has the same effect as the ''free'' library function found in [[C (programming language)|C]]) means that the risk of dangling pointers has not been eliminated<ref name="Hoare.Sneeringer.Welsh.1977">J. Welsh, W. J. Sneeringer, and C. A. R. Hoare, "Ambiguities and Insecurities in Pascal", ''Software: Practice and Experience 7'', pp. 685β696 (1977)</ref> as it has in languages such as Java and C#, which provide [[Garbage collection (computer science)|automatic garbage collection]] (but which do not eliminate the related problem of [[memory leak]]s). Some of these restrictions can be lifted in newer dialects.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Pascal (programming language)
(section)
Add topic