NCCU 資訊碩專班 Advanced Programming Languages
|
|
- Kerry Alexander
- 5 years ago
- Views:
Transcription
1 NCCU 資訊碩專班 Advanced Programming Languages 高等程式語言 Instructor: 資科系陳恭副教授 Spring 2006 Lecture 5: Variables, Assignment, Block, Store
2 More Semantic Concepts Variable Model Binding Concept Blocks and Scopes Memory Models Allocation/Deallocation Lifetime Garbage Dangling pointers
3 Variable Models Why? Analyze reality and find solutions
4 Models and Modeling A model is a simplification (abstraction) of reality. For analysis problems and finding solutions For prediction (theory) Modeling is the process that construct models. Models F = m * a Formal and informal models
5 Modeling Variables: A First Try A variable has a name and a value. So A intuitive and simplified model of variables: State (or Store) maps variable names to values directly State: Name Value Ex: if Sto(x) = 10; then x+5 will evaluate to 15 This is not capable of modeling variables in C/C++, Java, 觀察 : if Sto(x) = 10; how to interpret x = x + 5;? We need to refine the model! Let us first collect more examples for modeling.
6 Variables: Names, Locations & Values A variable is an abstraction of a memory cell The essential attributes of a variable name, location and value (some more later) Name: usually identifiers such as car, temp, sqrt, denote (refer to) a location Anonymous variables? Location: logical address, not real (physical) addresses Value: what can be stored in a location Typed values Primitive types: int, float, double, char, boolean, Composite types: structure in C (record in Pascal, COBOL), union in C, another location (pointer, reference), Principle operation on variables: Assignment x = 1; x = x + 1;
7 Motivating Examples There are two declarations of x. When we use x in bar(), which declaration are we using? Name resolution and name scope Scope rule Example: int x; void foo (int y) { float x; x = 100; bar(); } Void bar() { print(x); // which declaration of x? } int main() { x = 1; foo();... }
8 Motivating Examples What s wrong with the function dp? What does kp points to after the execution of do? What s wrong with the function garbage? Does it consume too many unneeded memory spaces? Memory allocation Examples: int *dp(int i) { int k, *kp; k = i; kp = &k; return kp; } int garbage(int c) { toy_t *tp; int total= 0; tp = (toy_t *) malloc(c*sizeof(toy_t)); tp->price = discount(price);... total = tp_price * c; return total; }
9 Basic Semantic Concepts Variables in Imperative Languages Variable & Assignment Binding and Binding Time Values and Types Type Binding Scope Memory lifetime
10 Variables and Assignment We use the name of a variable to refer to (denote) both its location and its stored value. Location vs. Value x = x + 1; The same x denotes two different meanings! L-values vs. R-values The right x is implicitly dereferenced to obtain the value stored therein. Some languages require explicit dereferencing (!): X = ref 0; x =!x + 1; (SML)
11 L-values and R-values memory: a very large array 9 0x7B1 0x7B1: 9 For a variable, by L-values: we mean locations (label on the box) R-values: we mean stored values (contents of the box)
12 A New Model of Variables We need a two-level mapping from variable names to their values. Two mappings: Environment and Store (state) Environment Store Names Locations Values x = x + 1; The left x is mapped to a memory location (address) by Env; The right x is mapped to a memory location by Env and then the value stored therein by the Sto.
13 The New Model Can model variables of different kinds: Pointers Variables whose values are other variables locations int i = 0, *ip = &i; Sto(Env(ip)) == Env(i) Call-By-Reference int f(int & x) { x = x+1; return x; } The argument s location, instead of value, is passed. Aliases int y = 5; i = f(y); During the execution of f, x is an alias of y. Any changes to x will affect y s value.
14 The Environment Environment: Names (Id) Locations How is the environment constructed? Viadeclarations! int x, y; We say the above declaration binds x and y to two different locations, which info is kept in the environment. How about procedure/function declarations? int double(int n) { return n+n; } Similar to variable declarations. But then we need to modify the def of Env.
15 Environment and Binding The Environment keeps the bindings of names declared by the programmer and those of predefined names, too. double is a user-defined function printf is a predefined procedure Binding: associate names with their values We need to modifies the ranges of an environment Env: Names Locations X Environment: Names (Denotable) Values for now denotable values = { primitive values} {function values} {Locations} Literals such as 1, 1,5
16 General Binding Concepts
17 Names & Identifiers A name is a mnemonic character string (identifier) representing (denoting, referencing) something else. Or to use names for particular entites, we introduce identifiers. Language identifiers: Keywords vs. Reserve words if, else, case,... User defined identifiers: Variables names Symbolic constants Function/Procedure names Data type names...
18 Binding In PLs many constructs can be given names. A fundamental semantics step: deduction of the meaning of a (user-defined) name: What does the name denote? What are its attributes?... x... y... max(x, y)... An (named) entity has associated with it a set of attributes Binding is the process of associating an attribute (value, meaning) to a name (symbol). attributes of named entitys variable: memory location, type, value name, scope, life time Named entity Binding Attributes (Values)
19 Binding Constructs Pre-defined bindings Reserved words: if, else, case, Operators:!, +, -, =, Declarations are the major binding constructs for programmers to introduce new bindings Variable declarations int x ; #define in C #define PI Function declarations int max(int x, nt y) { } x --> location, type PI --> a float value max --> a function Type declarations typedef date int; date a type alias of int
20 Binding Time Binding time is the time at which a binding takes place. Possible binding times: Language design time--e.g., bind operator symbols to operations! means logical negation in C Language implementation time--e.g., bind floating point type to a representation Compile time--e.g., bind a variable to a type in C or Java Link time extern variables in C Load time--e.g., bind a FORTRAN 77 variable to a memory cell (or a C static variable) Runtime--e.g., bind a nonstatic local variable to a memory cell Early vs. Late Binding
21 Binding Time Examples Operators: Syntax of + at language definition time Semantics of + at language definition time (Pascal) Semantics of + also at compile time (Ada, C++) + is overloaded -- which operator? -- at compile time Overloading ( 多載 ) 一個名字 / 運算子有多個意義, 視使用時的前後文決定其意義 3+5 vs vs. a + bcd Come back later. Late binding implies slower execution
22 Variable: Location, Value, Type 一變數的 location 內存的 value 可隨時透過 assignment 改變, 但其 location 的大小? 是否不宜改變? 一變數的 location 內存的 value 的種類是否固定? x = 1; x = 1.5; x = a string ; Type: values 的種類 ( a type is a set of values) int = {, -3, -2, -1, 0, 1, 2, 3, } float = {, -1.1,, 0.0,, 1.1, } Type binding: 變數宣告建立變數 name 與其 location 的對應外, 也可限定該 location 可存的 value 的種類 (type), 或者是說限定了該變數的 type. int x;
23 Type Binding 1/2 Is type an essential binding for a variable? Yes for static languages such as C/C++, and Java No for dynamic languages such as Lisp (Scheme), Prolog, and Scripting languages such as PHP, Perl (Storable) Values are typed; but Variables may not. In static languages, variables are typed: By an explicit declaration: int i; char *cp; By an implicit declaration: naming convention integer vars in Fortran: variable names beginning with letters i..n, e.g., I, N, Key string vars in Basic: variable names ending with $, e.g., astr$ Type inference (next slide) In dynamic languages, variables do not have fixed types, but depending on their values. For example, in Scheme (define var) ;; declar a variable named var without type binding (set! var 100) (set! var (a list now))
24 Type Binding 2/2 In summary, two kinds of type binding : Compile-time: static type bindingc/c++, Java, Run-time: dynamic type binding Lisp (Scheme), Prolog, APL, PHP, Perl, Usually, static type binding provides more efficient storage management because the types determine the size of locations. char c; // one or two bytes, fixed c = this cannot happen! ; C = D; // illegal, either The size of a location is fixed simple and efficient Static type binding Simple: type declarations Complex: type inference Type inference: Infer the type of a variable or an expression from context information; no need to declare types for every identifiers.
25 Type Inference Infer types without explicit type declarations Big topic in recent programming language research How many type declarations can you omit? Tied to polymorphism head: List(T) -> T l : List(float) head(l): float
26 Type Inference example function factorial ( x :? ) :?; begin if x = 0 then factorial := 1; else factorial := x * factorial(x - 1); end; We can infer that factorial returns an integer value because it returns a 1, and we can infer that x is An integer because we compare it to an integer. We could then check all the calls to factorial to determine if they passed an integer. head: List(T) -> T l : List(float) head(l): float
27 Summary of Type Binding When does the binding take place Explicit declaration (static type binding) Implicit declaration (static type binding) Type Inference (static) Determined by context and value (dynamic) Dynamic Type Binding When a variable gets a value, the type of the variable is determined right there and then.
28 Static vs. Dynamic Binding A binding is static if it first occurs before run time and remains unchanged throughout program execution. #define in C/C++ A binding is dynamic if it first occurs during execution or can change during execution of the program. Values of variables Location bindings (later) Type binding in Scheme (later)
29 Scopes
30 Motivating Scopes Given multiple bindings of a single name (identifier), how do we know which binding does an occurrence of this name refer to? Two bindings for x One of type int Another float An occurrence of x int x; void foo (int y) { float x; x } int main() { foo(x); // which binding of x?... }
31 Scope Scope of a Binding (declaration) the region of the program over which the binding is maintained Scope of a Name (abuse of the term scope ) the same name may declared multiply these different declarations of the same name should be differentiated Example: Local scope vs. Global scope int X; has a global scope float X; has a local scope. int X = 0; void foo (int X) { float X; X = // which X? } int main() { int y; foo(x); // which X?... }
32 Block and Scope Block a standard language construct which may contain declarations unit of scope and memory allocations Declaration before Use Rule: The scope is typically extends to the end of the block which contains the declaration Kinds of Blocks procedural block: Pascal non-procedural block: Ada, C ({ }) -- Ada example declare x: integer; begin end (* Pascal example *) program ex; var x: integer begin end
33 An Example of Block Scope in C int x; void p(void) { int i; } void q(void) { int j; } main() { int k; } i j k main q p x
34 Scope Holes What is a scope hole? a local declaration of a name can mask a prior declaration of the same name in this case, the masked declaration has a scope hole over the corresponding block Visibility and Scope Visibility: the region where the declared name is visible (excluding scope holes) Scope: the region where the binding exists (including scope holes)
35 Scope and Visibility: An Example in C int i=0; void p(void) { int i=2; } void q(void) { int j; } main() { int i; } i j i i scope hole i i scope hole scope visibility
36 Nested Blocks Block-Structured Program The program is consisted of blocks, which may be nested Most Algol descendants exploit this structure Nested blocks: Variables can be hidden from a unit by having a "closer" variable with the same name (scope hole) C and C++: for (...) { int index; { int k, index;... } } Lisp: (let ((a 1) ) (b foo)) (let ((c ) (+ a b))) (if (eq? b 0) c (else (* a b)))
37 Example: Identifier Scopes in ANSI C Block scope (local): float f ; { int a;... }... {int b;... } scope of variable a scope of variable b File Scope: Declared outside any blocks or functions, or function prototype ( f above) current file global
38 File Scope in C File Scope In C, a global name can be turned into a file scope name by attaching the keyword static. A file scope name can only be referenced in that file. Example File 1 extern int x;... x... File 2 int x;... x... File 3 static int x;... x...
39 ANSI C Scopes (Cont d) Function prototype: Scope of formal parameters: int foo(int n); scope of parameter n Function Scope: only for labels: void foo() {... goto lab;... lab: i++;... goto lab;... } scope of label lab, Note in ANSI-C all labels have function scope regardless of where they are
40 Scope Resolution Operator (::) of C++ // C++ example int x; void p(void) { char x; x = 'a'; // local x ::x = 42; // global x... } /* p */ main() { x = 2; // global x... } The global integer variable x has a scope hole in the body of p. In C, the global x cannot be referenced in p. In C++, the global x can be referenced in p using a scope resolution operator ::. Ada also has a scope resolution operator..
41 Scopes and Scope Rules The non-local variables of a program unit are those that are visible but not declared there We need some rules to locate corresponding declarations for nonlocal references. (name resolution) Local first; i.e., searching from the current environment Where then to find the binding for reference to non-local variables Non-local variable int X; void foo (int z) { X // which X? } int main() { int X; foo();... }
42 Scope Rules (for Non-locals) Static (Lexical) scope most languages Based on program text Search enclosing scope until the proper binding found Dynamic scope (older versions of Lisp) Based on program execution Trace the function calling-chain to find the proper binding Non-local variable int X; // this X, if static scope void foo (int z) { X // which X? } int main() { int X; // this X, if dynamic scope foo();... }
43 Static vs. dynamic scoping program MAIN; var a : integer; procedure P1; begin static (lexical) non-local variables are bound based on program structure MAIN print a; end; {of P1} if not local, go out a level example prints 7 P1 P2 procedure P2; var a : integer; begin a := 0; P1; end; {of P2} dynamic non-local variables are bound based on calling sequence MAIN P2 begin a := 7; if not local, go to calling point P1 P2; end. {of MAIN} example prints 0
44 Example: Static vs. Dynamic Scope int x = 1; char y = a ; void p(void) { double x = 2.5; printf( %c\n, y ); { int y[10]; } } void q(void) { int y = 42; printf( %d\n, x ); p(); } main() { char x = b ; q(); return 0; } Non-local Static scope: q(): print 1 p(): print a Dynamic scope: q(): print 92 ( b ) p(): print * (42) 呼叫執行順序 : MAIN calls q() q calls p() p uses nonlocal y
45 Nested scopes program MAIN; var a : integer; procedure P1(x : integer); procedure P3; begin print x, a; end; {of P3} begin P3; end; {of P1} many languages allow nested procedures static scoping example prints 1, 7 MAIN P1 P2 P3 procedure P2; var a : integer; begin a := 0; P1(a+1); end; {of P2} begin a := 7; P2; end. {of MAIN} dynamic scoping example prints 1, 0 MAIN P2 P1 P3
46 Name Bindings and Reuse Name Reuse, Multiple bindings 1. The same name is used to denote different entities in different categories. 2. The same name (identifier) can be bound to different things at different points in the program. 1. Name spaces 相同名字但不同 names pace, 不牴觸 package Reuse; // 極端案例 class Reuse { Reuse Reuse(Reuse Reuse) { Reuse: for (;;) { if (Reuse.Reuse(Reuse) == Reuse) break Reuse; } return Reuse; } } 2. 各有地盤 int X; void foo (int y) { float x; x } int main() { foo(x);... }
47 Name Spaces A general terms and also a special term in C++ ANSI C recognizes four distinct name spaces: one for tags, one for labels, one for members of a particular struct or union, and one for everything else. C++ namespaces are optionally named scopes, like packages in Java. Scopes are more complicated.
48 Memory Model & Management Storage Allocation/Deallocation Runtime Stack and Heap Lifetime Garbage and Dangling Pointers Misc.
49 Memory Model 程式執行期間記憶體的使用管理 : 程式碼部分比較單純 大型常數集中儲存 (constant pool) 但變數所需要的記憶體空間是如何決定的? Executable Image Code Constant(literal) pool 變數記憶體配置 靜態 動態 Data
50 Static Memory Model 早期程式語言 ( 如 Fortran) 的變數的配置是完全靜態的, compiler 編譯時即算出所有變數 ( 含副程式參數 ) 需要的記憶體空間及相對位置, 待程式載入執行時這些變數的位置就固定 (Load-time), 直到程式結束
51 Static memory model Cannot Support Recursion program test procedure p(x : short) var s, r: short; begin P(0); end procedure q(y : short) begin p(4); end begin q(2); p(3); end instruction memory <p> JUMP <p> JUMP <q> JUMP <p> <q> <main> data memory s (of p) r (of p) x (of p) y (of q)
52 Memory Model: Runtime Stack 靜態配置的作法雖然效率好, 但因為赴程式的參數與本地變數都只有固定的位置, 缺乏彈性且無法支援 recursion 現在的程式語言多是依不同需求, 將靜態 動態配置搭配, 兼顧效率與彈性, 所以不同種類的變數有不同的配置方式 首先, 要支援 recursion, 引進了 runtime stack 的作法 用它來儲存副程式的參數與本地變數等資訊, 並透過其先進後出的特性來支援 recursion 完整的記憶體支援需要配置位置儲存副程式的 參數與本地變數 執行結果 ( 回傳值 ) 返回位址 (return address) 其他環境資訊 ( 詳見第 6 單元 ) 所以一個副程式被呼叫執行時, 會動態配置 push 一個 activation record (stack frame) 給它儲存以上資訊 ; 副程式結束後並自動 pop 掉其 action record
53 An Activation Record (Stack Frame) Parameters Return address Dynamic link Static link Return value Local variables Runtime Stack grows as functions are called Static area Oldest frame Second Oldest frame Newest frame Details left to the Compiler course
54 Runtime Stack Memory program test procedure p(x : short) var s, r: short; begin end procedure q(y : short) begin p(4); end begin {main} q(2); p(3); SP end
55 Runtime Stack Memory program test procedure p(x : short) var s, r: short; begin end procedure q(y : short) begin p(4); end begin q(2); p(3); end SP y = 2 PC (return addr) Activation Record for q (frame)
56 Runtime Stack Memory program test procedure p(x : short) var s, r: short; begin end procedure q(y : short) begin p(4); end begin q(2); p(3); end SP s r x = 4 PC (return addr) y = 2 PC (return addr) Activation Record for p Activation Record for q
57 Runtime Stack Memory program test procedure p(x : short) var s, r: short; begin end procedure q(y : short) begin p(4); end begin q(2); p(3); end SP y = 2 PC (return addr) Activation Record for q
58 Runtime Stack Memory program test procedure p(x : short) var s, r: short; begin end procedure q(y : short) begin p(4); end begin q(2); p(3); SP end
59 Runtime Stack Memory program test procedure p(x : short) var s, r: short; begin end procedure q(y : short) begin p(4); end begin q(2); p(3); end SP s r x = 3 PC (return addr) Activation Record for p
60 Runtime Stack Memory program test procedure p(x : short) var s, r: short; begin end procedure q(y : short) begin p(4); end begin q(2); p(3); SP end
61 Limitations of Static Allocation Stack 上 activation record 的大小由 compiler 計算得出, 所以 the size of all data objects must be known at compile time No dynamic arrays Data structures cannot be created dynamically No variable length data like linked lists and trees No complicated return values
62 Memory Model: Heap Dynamic Allocation 除了 runtime stack 方式的動態配置外, 很多程式語言還支援由程式設計師自行控制的動態記憶體配置方式, 可用來製作像串列 (linked list) 等的動態資料結構 例如 :C 語言中的公用函式 malloc();c++/java 語言的 new 這些動態配置的記憶體區稱為 Heap, 是在 stack 以外的一塊記憶體空間 動態配置記憶體管理相關名詞 : Memory allocation: 從可用記憶體分配適當位置空間給變 ( 參 ) 數 Memory deallocation: 將變 ( 參 ) 數所使用的記憶體回收成可用記憶體 Memory allocation/deallocation 可由系統自動執行或由程式設計師於程式內 ( 在執行期間 ) 觸發 不同區間儲存了不同類型的變數資料
63 Categories of Variables Static variables 常數, 全域, 靜態變數 靜態配置 Stack-dynamic variables (Implicit allocation/deallocation) 參數, 本地變數, 函數返回值 由 runtime system 自動在副程式呼叫時動態配置與收回 Heap-dynamic variables 可由系統自動執行 (Implicit allocation) Example in Lisp: (set! list ( )) 系統自動配置記憶體給串列 ( ) 或由程式設計師於程式內 ( 在執行期間 ) 觸發 (Explicit allocation) Example in C Person *p ; p = (Person *) malloc( sizeof Person); p->name = Mike ; p->age = 40; free(p); Constructor ( new ) in Java and C++
64 Complete Memory Model 現代程式語言絕大多數都支援下列的 Memory model 常數, 全域, 靜態變數 參數, 本地變數, 函數返回值 動態變數 ( 透過指標存取 )
65 Summary Only Static Allocation Efficient Historic-sensitive Cannot support recursion Cannot support dynamic data structures (e.g. linked list) With Runtime Stack & Heaps More flexible Less efficient (management overhead) Support recursion (stack) Support dynamic data structures (Heap) Non-local variables access and Procedure parameters are not discussed yet
66 Lifetime (Extent) The lifetime of a storage location is the time between the location is allocated and deallocated. (The lifetime of a variable is the time during which it is bound to a particular memory cell.) The longest lifetime is the whole execution time of the program. Global and static variables Program execution time Creation of an object Object lifetime Destruction of an object
67 Blocks A common type of fixed lifetime is the time executing a block of a function/procedure. A block is a section of code in which local variables are allocated/deallocated at the start/end of the block. Introduced by ALGOL 60 and found in most PLs. Often being referred to as block-structured languages. C and C++: for (...) { int index; {... } } Ada: declare LCL : FLOAT; begin... end Nested blocks Scheme: (let* ((a 1) (b foo) (c)) (set! a (* b c)) (bar a b c))
68 Example of C Run-Time Stack A: { int x; char y; B: { double x; point 1 int a; } /* end B */ C: { char y; int b; D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Manipulation
69 Example of C Run-Time Stack A: { int x; char y; B: { double x; int a; } /* end B */ point 2 C: { char y; int b; D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Manipulation
70 Example of C Run-Time Stack A: { int x; char y; B: { double x; int a; } /* end B */ C: { char y; point 3 int b; D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Manipulation
71 Example of C Run-Time Stack A: { int x; char y; B: { double x; int a; } /* end B */ C: { char y; int b; point 4 D: { int x; double y; } /* end D */ } /* end C */ } /* end A */ Manipulation
72 Example of C Run-Time Stack A: { int x; char y; B: { double x; int a; } /* end B */ C: { char y; int b; D: { int x; double y; point 5 } /* end D */ } /* end C */ } /* end A */ Manipulation Stack-allocated variables: Lifetime 隨 block 而定, 規則式的
73 Lifetime of Heap-Allocated Variables Programmer allocated: lifetime begins when malloc() is called Constructor ( new ) is called System allocated When data structures requested (set! lst (a b c)) Deallocation when free() is called (Explicit de-allocation) Destructor is called (Explicit de-allocation) Garbage collector executed (Implicit de-allocation) 不規則
74 Garbage/Memory Leak Heap-allocated variables are sometimes called anonymous variables, and can only be accessed through pointers. Garbage: memory (heap) cell that is allocated but cannot be accessed. No pointers reference it. void f(void) { Person *p; p = (Person *) malloc(sizeof Person); p->name = Mike ; } Garbage Collection (GC): periodically sweeps the heap looking for data that cannot be accessed any more by the program and adding it back to free space. (Java, Lisp) Takes time and space!
75 Stack and Heap Review public class Strings { public static void test () { A StringBuffer sb = new StringBuffer B ("hello"); } } 1 2 static public void main (String args[]) { test (); test (); } sb Stack Heap java.lang.stringbuffer hello 1 When do the stack and heap look like this?
76 Stack and Heap Review public class Strings { public static void test () { StringBuffer sb = new StringBuffer B ("hello"); } } 2 static public void main (String args[]) { test (); test (); } sb Stack Heap java.lang.stringbuffer hello 2 1 hello
77 Garbage on the Heap public class Strings { public static void test () { StringBuffer sb = new StringBuffer ("hello"); } Stack Heap } static public void main (String args[]) { while (true) test (); } hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello
78 Dangling Pointers Dangling pointers: pointers that point to deallocated memory locations. Mostly: deallocated heap area. Person *p; p = (Person *) malloc(sizeof Person); p->name = Mike ; q = p; free(p); q->age = 40; In C, there are dangling pointers pointed to stack area, too. int *ip, k; { int i = 10; ip = &i; } k = *ip; De-allocated
79 Summary: Dangling Pointers and Garbage Dangling Pointer A: delete (free) A B: 0.4 B: Garbage (lost heap-dynamic variables) A: 7.2 A: 7.2 B: 0.4 B: 0.4
80 Summary: GC or not to GC? Explicit memory management is more efficient But manual deallocation errors are among the most common and costly bugs too fast deallocation dangling references forgotten deallocation memory leaks Automatic GC is considered an essential feature of modern languages GC algorithms have improved implementations are more complex in general (so adding GC plays not a big role) large applications make benefits of GC greater
81 Scope vs. Lifetime Scope and lifetime are sometimes closely related, but are different concepts. A counter example in C: // int counter = 0; int number; int count () { int counter=0 counter ++; return counter; } number = count(); number = count(); // Return 1 // Still 1 Local static variables int number; int count () { static int counter = 0; counter ++; return counter; } number = count(); number = count();
82 L-Values, Pointers and References
83 L-Values & Assignment Revisited Variables: named locations Modeling variables using two mappings: Environment and Store Environment Store Names Locations Values L-value R-value Assignments in C use implicit dereferencing of L-val to get R-val on RHS of assignments. x = x + 1; Assignments in ML: make dereferencing explicit val x = ref 0; x :=!x + 1;
84 Pointers in C/C++ pointer: a variable whose value is an l-value (e.g., the location of another variable) I.e., L-values are R-values, too. declaration: int * p; p address-of operator (&): & address_of: Producing R-val p = &x; p x Pointers make things more complex.
85 Pointers in C/C++: Manipulating L- values dereference operator (*): *p = 5; p x 5 pointers can point to pointers (multi-level pointers) int x; int *p; int **r; r = &p; **r = 10; p = &x; *p = 5; r p x 5 10
86 Pointers & Dereferencing On LHS of assignments: (producing L-val) As-is: p = ( ) malloc( ); p = & x; Explicit dereferencing: *p = 5; r = &p; **r = 10; p x On RHS of assignments: (producing R-val) Explicitly dereferenced and plus an implicit dereferencing : *p = *p + 5; As-is: pointer arithmetic p = p + 2; *r = *r + 2; r When a pointer that is pointing to memory you are not allowed to access is dereferenced, the result is a program crash via a "segmentation fault"
87 Issues of C/C++ Pointers Address_of operator & Ad-hoc restrictions &i, &a[0], &struct, &s.val, Pointer arithmetic Are they pointers or integers? Pointers and arrays The confusing dereference operator * Aliasing Dangerous type cast int *ip = (int *) 0;
88 Aliases An alias occurs when the same location is bound to two different names at the same time. Direct and Indirect aliases x An alias can occurs at call-by-reference parameter passing More examples in C? Union labels are aliases Pointer aliases: indirect aliases int I; int *ip =&I; int *jp = ip; y
89 Examples of Indirect Aliases thru Pointers (References) int *x, *y; x = (int *) malloc(sizeof(int)); *x = 1; y = x; *y = 2; printf( %d\n, *x); x y 2 class ArrTest // Java { public static void main(string[] args) { int [] x = {1,2,3}; int [] y = x; x[0] = 42; System.out.println(y[0]); } }
90 C++ References: T & Pointers have too many problems; use references for specific situations to avoid the problems reference = alias name for an existing object syntax: Typename& varname;... "varname is reference to variable of Typename" float x = 42.1f; rpi, pi alias name... float& rx = x; rx, x rx = rx / ; cout << "x = " << x; const double pi = ; constdouble& rpi= pi; Implicit dereferencing rx = & y; // Error! read only reference! No need to dereference. No more magic arithmetic!
91 Reference Parameters & Aliasing Reference parameters in C++: Implicitly dereferenced void swap(int & ip, int & iq) // C++ reference parameters { int temp; temp = ip; ip = iq; iq = temp; i } j Not change to ip or iq int i = 1, j = 10; int m = 5, n = 3; swap(i, j); // i and j s locations are passed to swap ip points to i; iq points to j swap(m, n); // m and n s locations are passed to swap swap (j, j); // create aliases ip points to m; iq points to n m n
92 Aliasing Summary Alias extra name for something that already has a name (in the current scope) we may have several How are they created? Fortran: explicit declarations (equivalence) variant/union structures languages using pointers reference parameters They are considered bad because they create confusion and hard-to-track errors compilers can optimize much better if they know there s no aliasing
93 Object References in Java Java has no pointers. All Objects are referenced thru object references. Implicit dereferencing Java o1 o2 o2 = o1 o1 o2 Shallow copy vs. Deep Copy (Clone)
94 Semantics of variables Meaning of variable ( and thus assignment): I. variable has value-semantics, the variable contains the value assigned. II. Variable has reference-semantics, the variable contains as value a reference to the value assigned. From the point of view of assignment: given x = z; what does assignment copy from z to x? the location or the value of z? The value: value semantics. the location: reference semantics. Reference semantics is used in OOP. Particularly Smalltalk, Eiffel uses reference semantics, while Java uses reference semantics for objects and value semantics for primitive type values. Reference semantics give rise to aliases during assignment. Languages provide operations to actually make a copy of the value if desired.
95 General Assignments (optional) (General) Assignments: <Expression-L> := <Expression-R> evaluate <Expression-R> to get its r-value evaluate <Expression-L> to get its l-value store r-value in l-value L-values can be used as R-values, but NOT vice versa What are the legal L-value expressions in C? p+1 = 20; //??? No! *(p+1) = 20; // OK
96 Forms of L-values in C lvalue asgnop expression lvalue: identifier primary [ expression ] lvalue. identifier primary identifier * expression ( lvalue ) But in C++, we have refgen(x) = x + 100; primary: identifier constant string ( expression ) primary ( expression-listopt ) primary [ expression ] lvalue. identifier primary -> identifier int & refgen(int & w) { return w; }
Chapter 7. Digital Arithmetic and Arithmetic Circuits. Signed/Unsigned Binary Numbers
Chapter 7 Digital Arithmetic and Arithmetic Circuits Signed/Unsigned Binary Numbers Signed Binary Number: A binary number of fixed length whose sign (+/ ) is represented by one bit (usually MSB) and its
More informationChapter 7. Signed/Unsigned Binary Numbers. Digital Arithmetic and Arithmetic Circuits. Unsigned Binary Arithmetic. Basic Rules (Unsigned)
Chapter 7 Digital rithmetic and rithmetic Circuits igned/unsigned inary Numbers igned inary Number: binary number of fixed length whose sign (+/ ) is represented by one bit (usually M) and its magnitude
More information港專單一登入系統 (SSO) 讓本校的同學, 全日制及兼職老師只要一個登入帳戶, 便可同時使用由本校提供的網上系統及服務, 包括 Blackboard 網上學習平台, 港專電郵服務, 圖書館電子資料庫及其他教學行政系統.
港專單一登入系統 (SSO) 讓本校的同學, 全日制及兼職老師只要一個登入帳戶, 便可同時使用由本校提供的網上系統及服務, 包括 Blackboard 網上學習平台, 港專電郵服務, 圖書館電子資料庫及其他教學行政系統. 港專單一登入網站網址 http://portal.hkct.edu.hk (HKCT 之教職員, 學生 ) http://portal.ctihe.edu.hk (CTIHE 之教職員,
More informationJava 程式設計基礎班 (7) 莊坤達台大電信所網路資料庫研究室. Java I/O. Class 7 1. Class 7 2
Java 程式設計基礎班 (7) 莊坤達台大電信所網路資料庫研究室 Email: doug@arbor.ee.ntu.edu.tw Class 7 1 回顧 Java I/O Class 7 2 Java Data Structure 動態資料結構 Grow and shrink at execution time Several types Linked lists Stacks Queues Binary
More informationJAVA Programming Language Homework V: Overall Review
JAVA Programming Language Homework V: Overall Review ID: Name: 1. Given the following Java code: [5 points] 1. public class SimpleCalc { 2. public int value; 3. public void calculate(){ value = value +
More informationFigure 1 Microsoft Visio
Pattern-Oriented Software Design (Fall 2013) Homework #1 (Due: 09/25/2013) 1. Introduction Entity relation (ER) diagrams are graphical representations of data models of relation databases. In the Unified
More informationCS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline
CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can
More informationChapter 7 Pointers ( 指標 )
Chapter Pointers ( 指標 ) Outline.1 Introduction.2 Pointer Variable Definitions and Initialization.3 Pointer Operators.4 Calling Functions by Reference.5 Using the const Qualifier with Pointers.6 Bubble
More informationSSL VPN User Manual (SSL VPN 連線使用手冊 )
SSL VPN User Manual (SSL VPN 連線使用手冊 ) 目錄 前言 (Preface) 1. ACMICPC 2018 VPN 連線說明 -- Pulse Secure for Windows ( 中文版 ):... 2 2. ACMICPC 2018 VPN 連線說明 -- Pulse Secure for Linux ( 中文版 )... 7 3. ACMICPC 2018
More informationAttributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,
Chapter 5 Basic Semantics Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, and the Environment Variables
More informationUbiquitous Computing Using SIP B 朱文藝 B 周俊男 B 王雋伯
Ubiquitous Computing Using SIP B91902039 朱文藝 B91902069 周俊男 B91902090 王雋伯 Outline Ubiquitous Computing Using SIP 1. Introduction 2. Related Work 3. System Architecture 4. Service Example 1. Introduction
More informationFrame Relay 訊框中繼 FRSW S0/0 S0/1
Frame Relay 訊框中繼 將路由器設定為訊框中繼交換器以進行 frame relay 實驗 : 首先練習設定兩個埠的 frame relay switch FRSW S0/0 S0/1 介面 S0/0 介面 S0/1 102 201 DLI 102 DLI 201 Router(config)# hostname FRSW FRSW(config)# frame-relay switching
More informationOxford isolution. 下載及安裝指南 Download and Installation Guide
Oxford isolution 下載及安裝指南 Download and Installation Guide 系統要求 個人電腦 Microsoft Windows 10 (Mobile 除外 ) Microsoft Windows 8 (RT 除外 ) 或 Microsoft Windows 7 (SP1 或更新版本 ) ( 網上下載 : http://eresources.oupchina.com.hk/oxfordisolution/download/index.html)
More informationPC Link Mode. Terminate PC Link? Esc. [GO]/[Esc] - - [GO]/[Esc] 轉接座未放滿. Make auto accord with socket mounted? [GO]/[Esc] Copy to SSD E0000
Start SU-6808 EMMC Programmer V.0bd7 [ ]Link PC / [ ]Menu [ ] >.Select project.make new project.engineer mode.reset counter 5.Link to PC [ ] PC disconnected PC connected Select project SEM0G9C_A.prj Terminate
More information桌上電腦及筆記本電腦安裝 Acrobat Reader 應用程式
On a desktop or notebook computer Installing Acrobat Reader to read the course materials The Course Guide, study units and other course materials are provided in PDF format, but to read them you need a
More information一般來說, 安裝 Ubuntu 到 USB 上, 不外乎兩種方式 : 1) 將電腦上的硬碟排線先予以排除, 將 USB 隨身碟插入主機, 以一般光碟安裝方式, 將 Ubuntu 安裝到 USB
Ubuntu 是新一代的 Linux 作業系統, 最重要的是, 它完全免費, 不光是作業系統, 連用軟體都不必錢 為什麼要裝在 USB 隨身碟上? 因為, 你可以把所有的軟體帶著走, 不必在每一台電腦上重新來一次, 不必每一套軟體裝在每一台電腦上都要再一次合法授權 以下安裝方式寫的是安裝完整的 Ubuntu- 企業雲端版本 V. 11.10 的安裝過程, 若是要安裝 Desktop 版本, 由於牽涉到
More informationTwin API Guide. How to use Twin
Twin API Guide How to use Twin 1 目錄 一 Cycle Job------------------------------------------------------------------------------------P3 二 Twin Action Table-----------------------------------------------------------------------P4-5
More informationSoftware Architecture Case Study: Applying Layer in SyncFree
Software Architecture Case Study: Applying Layer in SyncFree Chien-Tsun Chen Department of Computer Science and Information Engineering National Taipei University of Technology, Taipei 06, Taiwan ctchen@ctchen.idv.tw
More informationJava 程式設計基礎班 (7) 劉根豪台大電機所網路資料庫研究室. Java I/O. Class 7 1. Class 7
Java 程式設計基礎班 (7) 劉根豪台大電機所網路資料庫研究室 Email: kenliu@arbor.ee.ntu.edu.tw 1 回顧 Java I/O 2 1 Java Data Structure 動態資料結構 執行的時候可以動態變大或縮小 類型 Linked lists Stacks Queues Binary trees 3 自我參考類別 (self-referential classes)
More information描述性資料採礦 Descriptive Data Mining
描述性資料採礦 Descriptive Data Mining 李御璽 (Yue-Shi Lee) 銘傳大學資訊工程學系 leeys@mail.mcu.edu.tw Agenda Cluster Analysis ( 集群分析 ) 找出資料間的內部結構 Association Rules ( 關聯規則 ) 找出那些事件常常一起出現 Sequence Clustering ( 時序群集 ) Clustering
More informationOracle Database 11g Overview
Oracle Database 11g Overview Charlie 廖志華倍力資訊資深系統顧問 Great Year for Oracle Database Database Market Database for SAP 14.3% 48.6% 9% 3% 17% 4% 15.0% 22.0% 67% Oracle IBM Microsoft Other
More informationProgramming Languages Third Edition. Chapter 7 Basic Semantics
Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol
More informationWhat is a Better Program?
軟體的特性 What is a Better Program? 軟體之所謂軟 因為沒有 硬性 不可變 不可挑戰的規則 好處 : 彈性很大, 山不轉路轉, 沒有標準答案, 正常運作就好 C++ Object Oriented Programming 壞處 : 很多小問題合在一起不斷放大, 到處藏污納垢, 沒有標準答案, 不知道到底對了沒有 解決方法 Pei-yih Ting Coding styles
More informationUAK1-C01 USB Interface Data Encryption Lock USB 資料加密鎖. Specifications for Approval
Product Definition C-MING Product Semi-finished Product OEM/ODM Product Component USB Interface Data Encryption Lock USB 資料加密鎖 Specifications for Approval Approval Manager Issued By Revision History Revision
More information虛擬機 - 惡意程式攻防的新戰場. 講師簡介王大寶, 小時候大家叫他王小寶, 長大後就稱王大寶, 目前隸屬一神祕單位. 雖然佯稱興趣在看書與聽音樂, 但是其實晚上都在打 Game. 長期於系統最底層打滾, 熟悉 ASM,C/C++,
王大寶, PK 虛擬機 - 惡意程式攻防的新戰場 講師簡介王大寶, 小時候大家叫他王小寶, 長大後就稱王大寶, 目前隸屬一神祕單位. 雖然佯稱興趣在看書與聽音樂, 但是其實晚上都在打 Game. 長期於系統最底層打滾, 熟悉 ASM,C/C++, 對於資安毫無任何興趣, 也無經驗, 純粹是被某壞人騙上台, 可以說是不可多得的素人講師!! 議程大綱 : 現今的 CPU 都支援虛擬化專用指令集, 讓 VM
More informationChapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes 長庚大學資訊工程學系 陳仁暉 助理教授 Tel: (03) 211-8800 Ext: 5990 E-mail: jhchen@mail.cgu.edu.tw URL: http://www.csie.cgu.edu.tw/jhchen All rights reserved. No part
More informationNames, Bindings, Scopes
Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not
More informationChapter 5. Names, Bindings, and Scopes
Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative
More informationSyntest Tool 使用說明. Speaker: Yu-Hsien Cheng Adviser: Kuen-Jong Lee. VLSI/CAD Training Course
Syntest Tool 使用說明 Speaker: Yu-Hsien Cheng Adviser: Kuen-Jong Lee yhc97@beethoven.ee.ncku.edu.tw VLSI/CAD Training Course Foreword Why testing? Class.2 Why Testing? Economics! Reduce test cost (enhance
More informationMultimedia Service Support and Session Management 鍾國麟
Multimedia Service Support and Session Management 鍾國麟 2003-9-31 1 1 Agenda Introduction What is Session? Definition Functions Why need Session Management 2G,Internet,3G SIP Basic Operation User Location
More informationMP3 Codec Design 吳炳飛教授. Chaotic Systems & Signal Processing Lab, CSSP Lab. CSSP Lab:
MP3 Codec Design 吳炳飛教授 國立交通大學 電機與控制工程學系 CSSP Lab: http://cssp.cn.nctu.edu.tw Chaotic Systems & Signal Processing Lab, CSSP Lab July 5, 2004 Chapter 1 Introduction to MP3 Chapter 1: Introduction to MP3
More informationChapter 5 Names, Binding, Type Checking and Scopes
Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?
More informationChapter 4 (Part IV) The Processor: Datapath and Control (Parallelism and ILP)
Chapter 4 (Part IV) The Processor: Datapath and Control (Parallelism and ILP) 陳瑞奇 (J.C. Chen) 亞洲大學資訊工程學系 Adapted from class notes by Prof. M.J. Irwin, PSU and Prof. D. Patterson, UCB 4.10 Instruction-Level
More informationMid-term EXAM. 11/14/2009
Mid-term EXAM. 11/14/2009 1. (15%) Data Compression a) Encode the following characters using Huffman coding with the given frequencies: A(12), B(8), C(9), D(20), E(31), F(14), G(8) (-1 point if theree
More informationUNIX Basics + shell commands. Michael Tsai 2017/03/06
UNIX Basics + shell commands Michael Tsai 2017/03/06 Reading: http://www.faqs.org/docs/artu/ch02s01.html Where UNIX started Ken Thompson & Dennis Ritchie Multics OS project (1960s) @ Bell Labs UNIX on
More information2009 OB Workshop: Structural Equation Modeling. Changya Hu, Ph.D. NCCU 2009/07/ /07/03
Amos Introduction 2009 OB Workshop: Structural Equation Modeling Changya Hu, Ph.D. NCCU 2009/07/02- 2 Contents Amos Basic Functions Observed Variable Path Analysis Confirmatory Factor Analysis Full Model
More information用於網頁版權保護的資訊隱藏方法. A Steganographic Method for Copyright Protection of Web Pages
用於網頁版權保護的資訊隱藏方法 A Steganographic Method for Copyright Protection of Web Pages Ya-Hui Chang( 張雅惠 ) and Wen-Hsiang Tsai( 蔡文祥 ) Department of Computer & Information Science National Chiao Tung University
More information購票流程說明 How To purchase The Ticket?
購票流程說明 How To purchase The Ticket? 步驟 1: 點選 登入 Click 登入 Login (You have to login before purchasing.) 步驟 2: 若已是會員請填寫會員帳號 密碼, 點選 登入 若非會員請點選 註冊 If you are the member of PB+, Please login. If not, please register.
More informationCLAD 考前準備 與 LabVIEW 小技巧
CLAD 考前準備 與 LabVIEW 小技巧 NI 技術行銷工程師 柯璟銘 (Jimmy Ko) jimmy.ko@ni.com LabVIEW 認證 Certified LabVIEW Associate Developer (LabVIEW 基礎認證 ) Certified LabVIEW Associate Developer LabVIEW 全球認證 40 題 (37 題單選,3 題複選
More information第九章結構化查詢語言 SQL - 資料定義語言 (DDL) 資料庫系統設計理論李紹綸著
第九章結構化查詢語言 SQL - 資料定義語言 (DDL) 資料庫系統設計理論李紹綸著 SQL 的資料定義語言 本章內容 建立資料表 修改資料表 刪除資料表 FOREIGN KEY 外鍵條件約束與資料表關聯性 2 資料定義語言可分為下列三種 : SQL 的資料定義語言 CREATE TABLE 指令 : 用來建立一個基底關聯表, 和設定關聯表相關的完整性限制 CREATE VIEW 指令 : 用來建立一個視界,
More informationUse of SCTP for Handoff and Path Selection Strategy in Wireless Network
Use of SCTP for Handoff and Path Selection Strategy in Wireless Network Huai-Hsinh Tsai Grad. Inst. of Networking and Communication Eng., Chaoyang University of Technology s9530615@cyut.edu.tw Lin-Huang
More information全面強化電路設計與模擬驗證. Addi Lin / Graser 2 / Sep / 2016
全面強化電路設計與模擬驗證 Addi Lin / Graser 2 / Sep / 2016 Agenda OrCAD Design Solution OrCAD Capture 功能應用 OrCAD Capture CIS 介紹 OrCAD PSpice 模擬與驗證 OrCAD Design Solution Powerful and Widely Used Design Solution Front-to-Back
More informationSPI 功能使用方法 Application Note
1 適用產品 :SM59R16A2 / SM59R08A2 2 SPI 使用概述 : SPI 通信使用 4 個引腳, 分別為 SPI_: 當 master 時資料輸出 ; 當 slave 時資料輸入 SPI_: 當 master 時資料輸入 ; 當 slave 時資料輸出 SPI_SCK: SPI 的時脈信號由 master 主控產生 ; 資料 ( 輸出及輸入 ) 和時脈同步 SPI_SS: 此引腳功能唯有當作
More informationRA8835. Dot Matrix LCD Controller Q&A. Preliminary Version 1.2. July 13, RAiO Technology Inc.
RAiO Dot Matrix LCD Controller Q&A Preliminary Version 1.2 July 13, 2009 RAiO Technology Inc. Copyright RAiO Technology Inc. 2009 Update History Version Date Description 1.0 July 13, 2009 Preliminary Version
More informationGPIB 儀器控制之概念及軟硬體介紹 研華股份有限公司 工業自動化事業群
GPIB 儀器控制之概念及軟硬體介紹 研華股份有限公司 工業自動化事業群 Outline 1. Introduction to Adavntech GPIB Card 2. Introduction to IEEE 488.1 3. Introduction to IEEE 488.2 & SCPI GPIB History General Purpose Interface Bus 由 HP 於
More informationCitrix CloudGateway. aggregate control. all apps and data to any device, anywhere
Citrix CloudGateway aggregate control all apps and data to any device, anywhere Agenda 1. What s Cloud Gateway? 2. Cloud Gateway Overview 3. How it works? What s Cloud Gateway? It s all about the apps
More informationOperating Systems 作業系統
Chapter 7 Operating Systems 作業系統 7.1 Source: Foundations of Computer Science Cengage Learning Objectives 學習目標 After studying this chapter, students should be able to: 7.2 Understand the role of the operating
More informationSystem Programming. System Software: An Introduction to Systems Programming. Leland L. Beck 3rd Edition Addison-Wesley, 1997
System Programming System Software: An Introduction to Systems Programming Leland L. Beck 3rd Edition Addison-Wesley, 1997 1 http://web.thu.edu.tw/ctyang/ 2 http://hpc.csie.thu.edu.tw/ 3 Score List Participation:
More informationInTANK ir2771-s3 ir2772-s3. User Manual
InTANK ir2771-s3 ir2772-s3 User Manual » InTANK...1» InTANK ir2771-s3 & ir2772-s3 產品使用說明... 10 V1.1 Introduction Thank you for purchasing RAIDON products. This manual will introduce the InTANK ir2771-s3
More informationEZCast Docking Station
EZCast Docking Station Quick Start Guide Rev. 2.00 Introduction Thanks for choosing EZCast! The EZCast Docking Station contains the cutting-edge EZCast technology, and firmware upgrade will be provided
More informationChapter Addressing Modes
Chapter 5 8051 Addressing Modes 1 Sections 5.1 Immediate and register addressing modes 5.2 Accessing memory using various address modes 2 Objective 程式中的資料可能是放在 Register 中, 或在 RAM 中某一位址上, 或在 ROM 一塊特殊區域放置資料,
More informationPassword Protection 此篇文章說明如何在程式中加入密碼保護的機制, 當程式開啟, 使用者必須先輸入使用者帳號及密碼, 若是合法使用者才能進入應用程式
Password Protection 此篇文章說明如何在程式中加入密碼保護的機制, 當程式開啟, 使用者必須先輸入使用者帳號及密碼, 若是合法使用者才能進入應用程式 Step 1. 使用 Visual C++ 6.0 產生一個 MFC Application 1) Project name: PasswordProtection 2) Project type: MFC AppWizard(exe)
More information臺北巿立大學 104 學年度研究所碩士班入學考試試題
臺北巿立大學 104 學年度研究所碩士班入學考試試題 班別 : 資訊科學系碩士班 ( 資訊科學組 ) 科目 : 計算機概論 ( 含程式設計 ) 考試時間 :90 分鐘 08:30-10:00 總分 :100 分 注意 : 不必抄題, 作答時請將試題題號及答案依照順序寫在答卷上 ; 限用藍色或黑色筆作答, 使用其他顏色或鉛筆作答者, 所考科目以零分計算 ( 於本試題紙上作答者, 不予計分 ) 一 單選題
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 4a Andrew Tolmach Portland State University 1994-2016 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.
More informationCS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University
CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.
More informationEdConnect and EdDATA
www.hkedcity.net Tryout Programme of Standardised Data Format for e-textbook and e-learning Platform EdConnect and EdDATA 5 December 2018 Agenda Introduction and background Try-out Programme Q&A 電子課本統一數據格式
More informationCSC 533: Organization of Programming Languages. Spring 2005
CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms
More informationRENESAS BLE 實作課程 Jack Chen Victron Technology CO., LTD 2015 Renesas Electronics Corporation. All rights reserved.
RENESAS BLE 實作課程 2016-01-21 Jack Chen Jack.chen@victron.com.tw Victron Technology CO., LTD AGENDA CS+ & Renesas Flash Programmer 安裝 3 Renesas Flash Programmer 燒錄介紹 6 CS+ 介面介紹 11 CS+ 開啟 Project & 使用教學 14
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More informationEZCast Wire User s Manual
EZCast Wire User s Manual Rev. 2.01 Introduction Thanks for choosing EZCast! The EZCast Wire contains the cutting-edge EZCast technology, and firmware upgrade will be provided accordingly in order to compatible
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from
More informationFrom Suffix Trie to Suffix Tree
Outline Exact String Matching Suffix tree an extremely powerful data structure for string algorithms Input: P and S. Output: All occurrences of P in S. Time: O( P + S ) Technique: Z values of PS. Z(i +
More information私有雲公有雲的聯合出擊 領先的運算, 儲存與網路虛擬化技術 靈活的計費模式與經濟性 支援廣大的商業應用場景 涵蓋各類型雲服務 類標準的企業資料中心架構 全球規模與快速部署. 聯合設計的解決方案可為客戶提供最佳的 VMware 和 AWS
私有雲公有雲的聯合出擊 領先的運算, 儲存與網路虛擬化技術 支援廣大的商業應用場景 類標準的企業資料中心架構 靈活的計費模式與經濟性 涵蓋各類型雲服務 全球規模與快速部署 聯合設計的解決方案可為客戶提供最佳的 VMware 和 AWS VMware Cloud on AWS 使用場景 A B C D 雲端遷移資料中心延伸災難備援次世代應用程式 Consolidate Migrate Maintain
More information使用 TensorFlow 設計矩陣乘法計算並轉移執行在 Android 上 建國科技大學資管系 饒瑞佶 2017/8
使用 TensorFlow 設計矩陣乘法計算並轉移執行在 Android 上 建國科技大學資管系 饒瑞佶 2017/8 Python 設計 Model import tensorflow as tf from tensorflow.python.tools import freeze_graph from tensorflow.python.tools import optimize_for_inference_lib
More informationEZCast Wire. User s Manual. Rev. 2.00
EZCast Wire User s Manual Rev. 2.00 Introduction Thanks for choosing EZCast! The EZCast Wire contains the cutting-edge EZCast technology, and firmware upgrade will be provided accordingly in order to compatible
More informationPreamble Ethernet packet Data FCS
Preamble Ethernet. packet Data FCS Destination Address Source Address EtherType Data ::: Preamble. bytes. Destination Address. bytes. The address(es) are specified for a unicast, multicast (subgroup),
More informationChapter 1 Introduction to Computers, the Internet, and the Web
Chapter 1 Introduction to Computers, the Internet, and the Web Java technologies are classified into three editions: 1. Standard (J2SE technology) 2. Micro (J2ME technology) 3. Enterprise (J2EE technology)
More informationJava 程式設計入門. 講師 : 陳昭源 CSIE, NTU September 28, 2005
Java 程式設計入門 講師 : 陳昭源 CSIE, NTU September 28, 2005 Outline Floating Point & Decimal Numbers Inheritance Polymorphism Design Principles Abstract Exercise Interface September 28, 2005 Page 2 Floating Point
More informationVersion Control with Subversion
Version Control with Subversion 指導教授郭忠義 邱茂森 95598051 1 Table of contents (1) Basic concepts of subversion (1)What is Subversion (2)Version Control System (3)Branching and tagging (4) Repository and Working
More information6. Names, Scopes, and Bindings
Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack
More informationSE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms
SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms
More informationIncrease Productivity and Quality by New Layout Flow
Increase Productivity and Quality by New Layout Flow Jonathan / Graser 16 / Oct / 2015 Design Process Introduction CONSTRAINTS PLACEMENT FANOUT BREAKOUT ROUTING DELAY (ATE) NET-GROUP Topology & Delay Physical
More informationBTC, EMPREX Wireless Keybaord +Mouse + USB dongle. 6309URF III Quick Installation Guide
BTC, EMPREX 6309URF III Quick Installation Guide Hardware Installation 1. Plug the dongle receiver connector into your available USB port on PC. 2. Make sure the batteries of the keyboard and mouse are
More informationThe notice regarding Participation Ways of our global distributor video conference on Feb. 5.
The notice regarding Participation Ways of our global distributor video conference on Feb. 5. On Feb.5, 2010 Los Angeles time, between 5:00 PM - 7:00 PM, we will convene an important global distributor
More information游家德 Jade Freeman 群智信息 / 敦群數位資深架構顧問
游家德 Jade Freeman 群智信息 / 敦群數位資深架構顧問 搜尋對企業的需求方案關係 微軟全面性的搜尋方案及應用價值 Enterprise Search 的基本架構 Microsoft Search Solution 物件模型與客製開發 Microsoft Search Solution 應用與案例 Q&A 每人每天會花 10 分鐘在找企業所需文件, 且還可能找不到! 整合的資料大都雜亂無章,
More informationInformation is EVERYTHING 微軟企業混和雲解決方案. November 24, Spenser Lin. Cloud Infra Solution Sales, Microsoft Taiwan
Information is EVERYTHING 微軟企業混和雲解決方案 November 24, 2016 Spenser Lin Cloud Infra Solution Sales, Microsoft Taiwan Value to business Applications and services drive future IT business value Efficiency Innovation
More informationLotusphere Comes to You 輕鬆打造 Web 2.0 入口網站 IBM Corporation
輕鬆打造 Web 2.0 入口網站 2007 IBM Corporation 議程 Web 2.0 新特性一覽 Web 2.0 入口網站主題開發 用戶端聚合技術 PortalWeb2 主題 開發 AJAX portlets 程式 總結 JSR 286 及 WSRP 2.0 對 AJAX 的支援 AJAX 代理 用戶端 portlet 編程模型 Web 2.0 特性一覽 WP 6.1 提供的 Web
More information多元化資料中心 的保護策略 技術顧問 陳力維
多元化資料中心 的保護策略 技術顧問 陳力維 現代化的資料保護架構 使用者自助服務 任何儲存設備 影響低 多種還原點選擇 (RPO) Application Server 完整全面的雲端整合 Network Disk Target 容易操作與深入各層的報表能力 管理快照與複製能力 Primary Storage 快速 可靠的還原 (RTO) 完整的磁帶 & 複製管理 單一整合的解決方案 企業級的擴充性
More informationProgramming Languages, Summary CSC419; Odelia Schwartz
Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design
More informationDVS-8501E/DVS-8501E-H 單路 H.264 數位影像編碼器
DVS-8501E/DVS-8501E-H 單路 H.264 數位影像編碼器 1 LEGAL The information in this publication has been carefully checked and is believed to be entirely accurate at the time of publication. CTC Union Technologies
More informationDr. Whai-En Chen. Institute of Computer Science and Information Engineering National Ilan University TEL: #340
IPv6 Transition ( 轉移機制 ) Dr. Whai-En Chen Assistant Professor Institute of Computer Science and Information Engineering National Ilan University wechen@niu.edu.twedu TEL: +886-3-9357400#340 http://alan.ipv6.club.tw
More informationChapter 2 (Part 2) Instructions: Language of the Computer
Chapter 2 (Part 2) Instructions: Language of the Computer 陳瑞奇 (J.C. Chen) 亞洲大學資訊工程學系 Adapted from class notes by Prof. C.T. King, NTHU, Prof. M.J. Irwin, PSU and Prof. D. Patterson, UCB 1 2.6 Logical Operations
More informationCOP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Robert van Engelen Overview Abstractions and names Binding time Object lifetime Object storage management Static allocation Stack allocation
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationChannel Python API Overview
Channel Python API verview The Channel API creates a persistent connection between your application and Google servers, allowing your application to send messages to JavaScript clients in real time without
More information購票流程說明 How To purchase The Ticket?
購票流程說明 How To purchase The Ticket? 步驟 1: 已是會員請點選 登入, 選擇 2016 WTA 臺灣公開賽 Taiwan Open tickets Step1:If You are the member, please Click 登入 Click to the column: 2016 WTA 臺灣公開賽 Taiwan Open tickets Click 登入
More informationProgramming Languages Third Edition. Chapter 10 Control II Procedures and Environments
Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing
More informationPrevious on Computer Networks Class 18. ICMP: Internet Control Message Protocol IP Protocol Actually a IP packet
ICMP: Internet Control Message Protocol IP Protocol Actually a IP packet 前 4 个字节都是一样的 0 8 16 31 类型代码检验和 ( 这 4 个字节取决于 ICMP 报文的类型 ) ICMP 的数据部分 ( 长度取决于类型 ) ICMP 报文 首部 数据部分 IP 数据报 ICMP: Internet Control Message
More informationAllegro SPB V16 Advance
Allegro SPB V16 Advance Allegro SPB 16.2 Advance Import Logic Back Annotate Netlist Compare Advanced Placement Constraint Management Differential Pair Import Logic Other Cadence Import Logic Other 利用 Other
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationAVG Anti-Virus User Manual. Document revision ( )
AVG Anti-Virus 2012 User Manual Document revision 2012.01 (27.7.2011) Copyright AVG Technologies CZ, s.r.o. All rights reserved. All other trademarks are the property of their respective owners. This product
More informationNetwork Programming Concepts
Network Programming Concepts Bi-Ru Dai Perface What is network? What is Internet? What is World Wide Web? Where are the programs executed? Network Programming 2 1 What is Network? A group of two or more
More informationDVS-8504E-H 四路 H.264 數位影像編碼器
DVS-8504E-H 四路 H.264 數位影像編碼器 1 LEGAL The information in this publication has been carefully checked and is believed to be entirely accurate at the time of publication. CTC Union Technologies assumes no
More informationThe Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.
The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees
More informationCSE 307: Principles of Programming Languages
CSE 307: Principles of Programming Languages Variables and Constants R. Sekar 1 / 22 Topics 2 / 22 Variables and Constants Variables are stored in memory, whereas constants need not be. Value of variables
More informationThread. Running several threads is similar to running several different programs concurrently, but with the following benefits:
Thread Running several threads is similar to running several different programs concurrently, but with the following benefits: Multiple threads within a process share the same data space with the main
More informationProgrammiersprachen (Programming Languages)
2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html
More information