Download presentation
Presentation is loading. Please wait.
1
1 Programming Languages Lecture 2
2
2 Control Structures Any mechanism that departs from straight-line execution: Any mechanism that departs from straight-line execution: Selection: if-statements Selection: if-statements Multiway-selection: case statements Multiway-selection: case statements Unbounded iteration: while-loops Unbounded iteration: while-loops Definite iteration: for-loops Definite iteration: for-loops Iterations over collections Iterations over collections transfer of control: gotos (considered harmful!) transfer of control: gotos (considered harmful!) unbounded transfer of control: exceptions, backtracking unbounded transfer of control: exceptions, backtracking Characteristic of Imperative languages Characteristic of Imperative languages All you need for a universal machine: increment, decrement, branch on zero. All the rest is programmer convenience! All you need for a universal machine: increment, decrement, branch on zero. All the rest is programmer convenience! Not efficient on modern pipelined processors Not efficient on modern pipelined processors
3
3 Selection if Condition then Statement else Statement-- Pascal, Ada if Condition then Statement else Statement-- Pascal, Ada if (Condition) Statement else Statement-- C, C++ Java if (Condition) Statement else Statement-- C, C++ Java Selection Expression: Condition ? Expression : Expression -- C Selection Expression: Condition ? Expression : Expression -- C Characteristic of functional languages Characteristic of functional languages To avoid ambiguities, use end marker: end if, fi, or bracketing { } To avoid ambiguities, use end marker: end if, fi, or bracketing { } To deal with several alternatives, use keyword or bracketing: To deal with several alternatives, use keyword or bracketing: --Ada/* C */ if Condition then if (Condition) { Statements Statements} Statements Statements} elsif Condition then else if (Condition) { Statements Statements} Statements Statements} else else { Statements Statements} Statements Statements} end if;
4
4 Statement Grouping Pascal introduces begin-end pair to mark sequence Pascal introduces begin-end pair to mark sequence C/C++/Java abbreviate keywords to { } C/C++/Java abbreviate keywords to { } Ada dispenses with brackets for sequences, because keywords for the enclosing control structure are sufficient: Ada dispenses with brackets for sequences, because keywords for the enclosing control structure are sufficient: for J in 1.. N loop … end loop; for J in 1.. N loop … end loop; More writing => more readable More writing => more readable The use of grouping in C++/Java is just syntactic tradition The use of grouping in C++/Java is just syntactic tradition Another possibility (ABC, Python): make indentation significant Another possibility (ABC, Python): make indentation significant Nesting groups of statements Nesting groups of statements if Condition then if (Condition) if Condition then if (Condition) { if Condition then if (Condition) { Statements Statements Statements Statements end if; } end if; } else else { else else { Statements Statements Statements Statements end if; } end if; }
5
5 Short-Circuit Evaluation If x is more than five times greater than y, compute z: If x is more than five times greater than y, compute z: if x / y > 5 then z := … -- but what if y is 0? if x / y > 5 then z := … -- but what if y is 0? if y /= 0 and x/ y > 5then z := … -- but operators evaluate their arguments if y /= 0 and x/ y > 5then z := … -- but operators evaluate their arguments Solutions: Solutions: a lazy evaluation rule for logical operators (LISP, C, etc) a lazy evaluation rule for logical operators (LISP, C, etc) a control structure with a different syntax a control structure with a different syntax C1 && C2 does not evaluate C2 if C1 is false C1 && C2 does not evaluate C2 if C1 is false if C1 and then C2 then ditto if C1 and then C2 then ditto C1 || C2 does not evaluate C2 if C1 is true C1 || C2 does not evaluate C2 if C1 is true if C1 or else C2 then ditto if C1 or else C2 then ditto
6
6 Multiway selection Generalization of condition if from boolean to any discrete type Generalization of condition if from boolean to any discrete type Can be simulated with a sequence of if-statements, but logic can become obscured. Can be simulated with a sequence of if-statements, but logic can become obscured. case (X) is -- any integer value (discrete but large) case (X) is -- any integer value (discrete but large) when integer’first.. 0=> Put_Line (“negative”); when integer’first.. 0=> Put_Line (“negative”); when 1 => Put_Line (“unit”); when 1 => Put_Line (“unit”); when 3 | 5 | 7 | 11 => Put_Line (“small prime”); when 3 | 5 | 7 | 11 => Put_Line (“small prime”); when 2 | 4 | 6 | 8 | 10 => Put_Line (“small even”); when 2 | 4 | 6 | 8 | 10 => Put_Line (“small even”); when 21 => Put_Line (“house wins”); when 21 => Put_Line (“house wins”); when 12.. 20 | 22.. 99 => Put_Line (“manageable”); when 12.. 20 | 22.. 99 => Put_Line (“manageable”); when others => Put_Line (“Irrelevant”); when others => Put_Line (“Irrelevant”); end case; end case; All choices must be computable at compile-time All choices must be computable at compile-time
7
7 The well-structured case statement Enforced in CAda Type of expression must be discrete: an enumerable set of values (floating-point numbers not acceptable) YY Each choice is independent of the others (no flow- through) NY All possible choices are covered exactly once NY There is mechanism to specify a default outcome for choices not given explicitly. YY
8
8 Loops Definite Loops Definite Loops for J in Integer range 1.. 10 loop statements end loop; for J in Integer range 1.. 10 loop statements end loop; Indefinite Loops Indefinite Loops while condition loop statements end loop; while condition loop statements end loop; loop statements end loop; loop statements end loop; All loops can be expressed as while-loops (e.g., in C) All loops can be expressed as while-loops (e.g., in C) for (i = 0; i <10; i++) … equivalent to: i=0; while (i<10) { … i++;} Condition is evaluated at each iteration Condition is evaluated at each iteration If condition is initially false, loop is never executed If condition is initially false, loop is never executed while Condition loop.. end loop; while Condition loop.. end loop; equivalent to equivalent to if Condition then if Condition then while Condition loop … end loop; while Condition loop … end loop; end if; end if;
9
9 What if we want to execute at least once? Pascal introduces until-loop. Pascal introduces until-loop. C/C++ use different syntax with while: C/C++ use different syntax with while: while (Condition) { … } do { … } while (Condition) Can always simulate with a boolean variable: Can always simulate with a boolean variable: done := False; while (not done) loop … … if Condition then done := True; if Condition then done := True; end loop;
10
10 Unstructured flow (Duff’s device) void send (int* to, int* from, int count) { int n = (count + 7 ) / 8; int n = (count + 7 ) / 8; switch (count % 8) { switch (count % 8) { case 0 : do { *to++ = *from++; case 7 : *to++ = *from++; case 6 : *to++ = *from++; case 5 : *to++ = *from++; case 4 : *to++ = *from++; case 3 : *to++ = *from++; case 2 : *to++ = *from++; case 1 : *to++ = *from++; } while (--n >0); } while (--n >0);} What does this do? Why bother?
11
11 Breaking out More common is the need for an indefinite loop that terminates in the middle of an iteration. More common is the need for an indefinite loop that terminates in the middle of an iteration. C/C++/Java: break C/C++/Java: break Break out of while, do, for, switch statements Break out of while, do, for, switch statements Ada : exit statement Ada : exit statement loop -- infinite loop compute_first_part; compute_first_part; exit when got_it; exit when got_it; compute_some_more; compute_some_more; end loop;
12
12 Breaking out of Nested Loops Within nested loops, useful to specify exit from several of them Within nested loops, useful to specify exit from several of them Ada solution: give names to loops Ada solution: give names to loops Otherwise: use a counter (Modula) or use a goto. Otherwise: use a counter (Modula) or use a goto. Outer: while C1 loop... Outer: while C1 loop... Inner: while C2 loop... Inner: while C2 loop... Innermost: while C3 loop... Innermost: while C3 loop... exit Outer when Major_Failure; exit Outer when Major_Failure; exit Inner when Small_Annoyance; exit Inner when Small_Annoyance;...... end loop Innermost; end loop Innermost; end loop Inner; end loop Inner; end loop Outer; end loop Outer;
13
13 Definite loops Counting loops are iterators over discrete domains: Counting loops are iterators over discrete domains: for J in 1..10 loop … for J in 1..10 loop … for (int I = 0; I < N; I++ ).. for (int I = 0; I < N; I++ ).. Design issues: Design issues: Evaluation of bounds (only once, ever since Algol60) Evaluation of bounds (only once, ever since Algol60) Scope of loop variable Scope of loop variable Empty loops Empty loops Increments other than one Increments other than one Backwards iteration Backwards iteration non-numeric domains non-numeric domains
14
14 The loop variable Best if local to loop and treated as constant Best if local to loop and treated as constant Avoids issue of value at termination, and value on abrupt exit Avoids issue of value at termination, and value on abrupt exit counter : integer := 17; -- outer declaration counter : integer := 17; -- outer declaration...... for counter in 1..10 loop for counter in 1..10 loop do_something; -- 1 <= counter <= 10 do_something; -- 1 <= counter <= 10 end loop; end loop; … … -- counter is still 17 -- counter is still 17
15
15 Different increments The universal Algol60 form: The universal Algol60 form: for J from Exp1 to Exp2 by Exp3 do… for J from Exp1 to Exp2 by Exp3 do… Too rich for most cases. Exp3 is most often +1, -1. Too rich for most cases. Exp3 is most often +1, -1. What is meaning if Exp1 > Exp2 and Exp3 Exp2 and Exp3 < 0 ? In C/ C++ In C/ C++ for (int J = Exp1; J <= Exp2; J = J + Exp3) … for (int J = Exp1; J <= Exp2; J = J + Exp3) … In Ada: In Ada: for J in 1.. N loop -- increment is +1 for J in 1.. N loop -- increment is +1 for J in reverse 1.. N loop -- increment is -1 for J in reverse 1.. N loop -- increment is -1 Everything else can be programmed with while-loop Everything else can be programmed with while-loop
16
16 Non-numeric domains Ada form generalizes to discrete types: Ada form generalizes to discrete types: for M in months loop … General pattern for other data-types: General pattern for other data-types: define iterator class with primitive operations: hasNext(), next() Iterator it = Collection.Iterator(); while (it.hasNext) { element = it.next(); element = it.next(); …} APL avoids the need for iterators by automatically extending scalar operations over composite data types APL avoids the need for iterators by automatically extending scalar operations over composite data types a 1 2 3 b 3 2 1 1 + a is 2 3 4 a + b is 4 4 4
17
17 Recursion Example: Example: int fib(int n) { return (n <= 1) ? 1 : fib(n-1) + fib(n-2); } Tail Recursion – when function returns immediately after recursive call – can be automatically transformed into a loop Tail Recursion – when function returns immediately after recursive call – can be automatically transformed into a loop List processing with recursion List processing with recursion int max(List list) { if (list.isEmpty()) { if (list.isEmpty()) { return Integer.min(); return Integer.min(); } else { } else { if (list.first() > max(list.deleteHead) { if (list.first() > max(list.deleteHead) { return list.first(); return list.first(); } else { } else { return max(list.deleteHead(); return max(list.deleteHead(); }}} }}}
18
18 Assignment Assignment always produces a side effect Assignment always produces a side effect variable := expression; variable := expression; lvalue := rvalue lvalue (left hand value) must be an address or reference. e.g., x, x[i] but not (x + 1) lvalue (left hand value) must be an address or reference. e.g., x, x[i] but not (x + 1) rvalue (right hand value) is a value rvalue (right hand value) is a value Types must match Types must match In Ada, assignment is a statement In Ada, assignment is a statement In C, C++, and Java it is an expression In C, C++, and Java it is an expression Initialization vs. Assignment Initialization vs. Assignment Combination Assignment Combination Assignment X = X + 1 -- a mathematical absurdity X = X + 1 -- a mathematical absurdity X += 1 -- simpler and clearer X += 1 -- simpler and clearer
19
19 Precedence & Associativity Most languages enforce standard mathematical rules Most languages enforce standard mathematical rules APL doesn’t. Evaluation is always right to left APL doesn’t. Evaluation is always right to left Same for Smalltalk Same for Smalltalk C++ has 18 levels of precedence C++ has 18 levels of precedence Even if you know them all, the next maintenance programmer might not Even if you know them all, the next maintenance programmer might not Use parentheses Use parentheses
20
20 Continuations A Continuation represents a point in the computation, including all of the state information at that point A Continuation represents a point in the computation, including all of the state information at that point All control structures (function calls, loops, if, exceptions, goto, etc.) can be described using continuations All control structures (function calls, loops, if, exceptions, goto, etc.) can be described using continuations Scheme supports continuations as 1 st class objects Scheme supports continuations as 1 st class objects
21
21 An Introduction to Ada
22
22 What’s ADA all about Designed by committee for DoD Designed by committee for DoD Key goals: Key goals: Readability Readability Strong typing Strong typing Detection of errors at compile time Detection of errors at compile time Programming in the Large – Packages Programming in the Large – Packages Encapsulation Encapsulation Separate compilation Separate compilation Data Abstraction Data Abstraction Run-time Error Handling – Exceptions Run-time Error Handling – Exceptions Reliable multi-Tasking Reliable multi-Tasking Generic Units – parameterized types Generic Units – parameterized types Emphasis on Programming as a Human Activity Emphasis on Programming as a Human Activity
23
23 Hello, World A simple Ada Program, hello.ada A simple Ada Program, hello.ada with text_IO; procedure hello is use text_IO; use text_IO;begin put(“Hello, World”); put(“Hello, World”); end hello;
24
24 Basic Structure of an ADA Program Program Units Program Units Packages, subprograms and tasks Packages, subprograms and tasks Subprograms Subprograms Procedures (do not return a value) Procedures (do not return a value) Functions (return a value) Functions (return a value) Packages Packages Collection of related data types Collection of related data types functions and procedures Provides services to clients Provides services to clients May use services of other packages May use services of other packages Defined in two parts Defined in two parts Package Specification (.ads,.spc) Package Specification (.ads,.spc) Package Body(.adb,.bdy) Package Body(.adb,.bdy)
25
25 Package Specification Contain Declarations Contain Declarations package X is declarations types subprogram specs (but not subprogram bodies) end X; package X is declarations types subprogram specs (but not subprogram bodies) end X; Specification provides public interface for users of the package, but no implementation details Specification provides public interface for users of the package, but no implementation details Specification is like a contract between the package and its clients Specification is like a contract between the package and its clients
26
26 Subprogram Specification procedure Print_In_Hex (X : Integer); function Max (A, B : Integer) return Integer; Similar to signatures in C and C++ header files. Similar to signatures in C and C++ header files. Headers can be generated automatically from the source code Headers can be generated automatically from the source code Java does this automatically with import statement Java does this automatically with import statement A subprogram spec has everything you need to know to use the subprogram A subprogram spec has everything you need to know to use the subprogram A client sees only the specification A client sees only the specification Implementation details are hidden Implementation details are hidden Implementation can be changed without affecting clients Implementation can be changed without affecting clients
27
27 Procedure Body procedure H (M : Integer) is declarations begin statements return; end H; procedure H (M : Integer) is declarations begin statements return; end H; Typical use is procedure Main is … which defines the main program Typical use is procedure Main is … which defines the main program File name must match main procedure name File name must match main procedure name
28
28 Function Body function Max (A : Integer; B : Integer) return Integer is Result : Integer; begin if A > B then Result := A; else Result := B; end if; return Result; end Max; function Max (A : Integer; B : Integer) return Integer is Result : Integer; begin if A > B then Result := A; else Result := B; end if; return Result; end Max;
29
29 Package Bodies Contain Definitions Contain Definitions package body X is declarations subprograms local to body variables/constants local to body subprogram bodies for subprogram specs appearing in the package spec begin initialization statements end X; package body X is declarations subprograms local to body variables/constants local to body subprogram bodies for subprogram specs appearing in the package spec begin initialization statements end X;
30
30 How to be a Client of a package To access a package, use With and Use statements: with Calendar, Text_IO; use Text_IO; procedure Main is Today : Calendar.Time; put(“Today is” ); … end Main; To access a package, use With and Use statements: with Calendar, Text_IO; use Text_IO; procedure Main is Today : Calendar.Time; put(“Today is” ); … end Main; Use eliminates the need to specify the package name, as in Calendar.Time, when using a package member Use eliminates the need to specify the package name, as in Calendar.Time, when using a package member
31
31 Package Clients Package Bodies Package Bodies with Calendar; package body Julian_Calendar_Stuff is … end Julian_Calendar_Stuff; Package implemented using another package Package implemented using another package Package Specifications Package Specifications with Calendar; use Calendar; package To_Do_List is … procedure Enter (T : Time; M : String); -- Enter new item in todo list. Time is -- deadline. M is description. end To_Do_List; with Calendar; use Calendar; package To_Do_List is … procedure Enter (T : Time; M : String); -- Enter new item in todo list. Time is -- deadline. M is description. end To_Do_List; Package To_Do_List extends Calendar interface Package To_Do_List extends Calendar interface
32
32 Using Ada Write your program using any text editor Write your program using any text editor Save it in a file named myprog.adb, where myprog is the name of the main procedure in the program. Save it in a file named myprog.adb, where myprog is the name of the main procedure in the program. Compile your program: Compile your program: gnat make myprog.adb On windows this produces a file myprog.exe, which you can execute On windows this produces a file myprog.exe, which you can execute On Unix you will have to make the file executable using chmod a+x myprog On Unix you will have to make the file executable using chmod a+x myprog Ada resources on the Web: Ada resources on the Web: http://www.adapower.com http://www.adapower.com http://www.adapower.com http://www.adahome.com http://www.adahome.com http://www.adahome.com ftp://cs.nyu.edu/pub/gnat ftp://cs.nyu.edu/pub/gnat ftp://cs.nyu.edu/pub/gnat
33
33 Writing an ADA Program Write the package specifications Write the package specifications Verify that specification is usable by intended clients Verify that specification is usable by intended clients Write the body Write the body Write the clients Write the clients Last two activities are completely independent (and should not talk to one another except “via” the spec) Last two activities are completely independent (and should not talk to one another except “via” the spec)
34
34 Ada Operators Logical Operators:and or xor Relational Operators: = /= >= Additive Operators:+ – & & is concatenation on vectors and strings Unary Operators:+ – not Multiplicative Operators: * / mod rem Exponentiation Operator: **
35
35 Integer Types Type Integer is built in – But you don’t want to use it! Type Integer is built in – But you don’t want to use it! In ADA types are defined according to use In ADA types are defined according to use type Day_In_Year is range 1.. 366; type Age is range 0.. 130; type Temperature is range -20.. +180; Now we can define variables of the type Now we can define variables of the type Today_Day : Day_In_Year; Employee_Age : Age; Machine_Room_Temp : Temperature; Type Attributes Type Attributes Integer’last, Year’last Integer’last, Year’last Integer’first, Age’first Integer’first, Age’first for A in Age’first … Age’last loop for A in Age’first … Age’last loop
36
36 Strong Typing No dependence on implementation -- Unlike type int in C No dependence on implementation -- Unlike type int in C Range of types matches problem Range of types matches problem Get an error or warning at compile time Get an error or warning at compile time Age := 200; Age := 200; Or an exception at runtime Or an exception at runtime Age := Age + 1000; Age := Age + 1000; Cannot mix integer types: Cannot mix integer types: Current_Temp : Temperature; OK Current_Pressure : Pressure; OK Current_Temp := Current_Pressure + 1; Error Current_Temp := Current_Temp + Current_Pressure; Error Type Errors detected at Compile Time Type Errors detected at Compile Time
37
37 Integer Subtypes A subtype creates a limited range A subtype creates a limited range But is still the same type But is still the same type subtype OK_Operating_Range is Temperature range 70.. 80; Room_Temp : Temperature; Machine_Room_Temp : OK_Operating_Range … Machine_Room_Temp := Room_Temp; subtype OK_Operating_Range is Temperature range 70.. 80; Room_Temp : Temperature; Machine_Room_Temp : OK_Operating_Range … Machine_Room_Temp := Room_Temp; Raises exception if Room_Temp out of range Raises exception if Room_Temp out of range
38
38 Enumeration Types An enumeration type is a sequence of ordered enumeration literals: An enumeration type is a sequence of ordered enumeration literals: Type State is (Off, Powering_Up, On); Type State is (Off, Powering_Up, On); Type Color is (Red, Orange, Yellow, Blue, Green); Type Color is (Red, Orange, Yellow, Blue, Green); Not integers (as in C++) Not integers (as in C++) S1, S2 : State; S1 := S1 + 1; – Error, but State’Pred (On) – OK, Powering_Up State’Succ (On) – OK, but raises constraint_error Predefined enumeration type Predefined enumeration type type Boolean is (False, True); type Boolean is (False, True); Other Attributes include: Other Attributes include: T’First, T’Last, T’Val(n) where n is a value in T
39
39 Character Types Built in types Built in types Character (8-bit Latin-1) Character (8-bit Latin-1) Wide_Character (16-bit Unicode/ISO 10646) Wide_Character (16-bit Unicode/ISO 10646) Good enough for most purposes, but you can define your own types: Good enough for most purposes, but you can define your own types: type My_Character is (‘A’, ‘B’, ‘C’, ….); type My_Character is (‘A’, ‘B’, ‘C’, ….);
40
40 String Types A string type is an array whose elements are a character type. A string type is an array whose elements are a character type. Two standard built in string types Two standard built in string types type String is array (Natural range <>) of Character; type Wide_String is array (Natural range <>) of Wide_Character; S : String (1.. 5) := “Hello”; type String is array (Natural range <>) of Character; type Wide_String is array (Natural range <>) of Wide_Character; S : String (1.. 5) := “Hello”; Note: Natural is a predefined subtype of Integer with bounds 0.. Integer’Last; Note: Natural is a predefined subtype of Integer with bounds 0.. Integer’Last;
41
41 Array Types Arrays can have 1 or more subscripts Arrays can have 1 or more subscripts type Vector is type Vector is array (Integer range 1.. 10) of Integer; type Matrix is array (Integer range 0.. 10, Character range ‘A’.. ‘Z’) of Vector; array (Integer range 1.. 10) of Integer; type Matrix is array (Integer range 0.. 10, Character range ‘A’.. ‘Z’) of Vector; VV : Vector; MM : Matrix; … MM (5, ‘C’) := VV;
42
42 Array Attributes A’First(N), A’Last(N), A’Length(N), A’Range(N) A’First(N), A’Last(N), A’Length(N), A’Range(N) N is the attribute for the Nth index N is the attribute for the Nth index N must be static N must be static Without a parameter, attributes refer to the first index - A’First, etc. Without a parameter, attributes refer to the first index - A’First, etc. We can use the array range in loops We can use the array range in loops for x in A’Range loop result := result + A[x]; end loop;
43
43 Unconstrained Arrays Unconstrained array type has no bounds Unconstrained array type has no bounds type UA is array (Int range <>) of Int; -- cannot use UA to declare a variable -- instead must build a subtype subtype UA5 is UA (1.. 5); UAV5 : UA5 := (6,5,4,3,2); -- can also set bounds for a variable UAV2 : UA (1.. 2); type UA is array (Int range <>) of Int; -- cannot use UA to declare a variable -- instead must build a subtype subtype UA5 is UA (1.. 5); UAV5 : UA5 := (6,5,4,3,2); -- can also set bounds for a variable UAV2 : UA (1.. 2);
44
44 Access Types Access types function like pointers Access types function like pointers But are not necessarily implemented that way But are not necessarily implemented that way type r is access integer; type r is access integer; Allocate an object using new Allocate an object using new type AI is access all integer; Ptr : AI; … Ptr := new Integer; -- uninitialized Ptr := new Integer’(12); -- initialized type AI is access all integer; Ptr : AI; … Ptr := new Integer; -- uninitialized Ptr := new Integer’(12); -- initialized To obtain value dereference: To obtain value dereference: V : Integer; … V := Ptr.all; V : Integer; … V := Ptr.all;
45
45 Declaring and Handling Exceptions Declaring an exception Declaring an exception Error, Disaster : exception; Error, Disaster : exception; Raising an exception Raising an exception raise Disaster; -- strips stack frames till a handler is found raise Disaster; -- strips stack frames till a handler is found Handling an exception Handling an exception exception when Disaster => statements exception when Disaster => statements
46
46 Catching Exceptions You can catch an exception at run time You can catch an exception at run time begin … Machine_Room_Temp := Room_Temp … exception when Constraint_Error => recovery stuff when Meltdown_Error => recovery stuff begin … Machine_Room_Temp := Room_Temp … exception when Constraint_Error => recovery stuff when Meltdown_Error => recovery stuff … end; … end;
47
47 Block Statement Block statement can be used anywhere Block statement can be used anywhere declare -- declare section optional declarations begin statements exception -- exception section optional handlers end; declare -- declare section optional declarations begin statements exception -- exception section optional handlers end;
48
48 Access Types Access types function like pointers Access types function like pointers But are not necessarily implemented that way But are not necessarily implemented that way type r is access integer; type r is access integer; Allocate an object using new Allocate an object using new type AI is access all integer; Ptr : AI; … Ptr := new Integer; -- uninitialized Ptr := new Integer’(12); -- initialized type AI is access all integer; Ptr : AI; … Ptr := new Integer; -- uninitialized Ptr := new Integer’(12); -- initialized To obtain value dereference: To obtain value dereference: V : Integer; … V := Ptr.all; V : Integer; … V := Ptr.all;
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.