Changes between Version 33 and Version 34 of IR2
- Timestamp:
- 04/28/21 15:04:24 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
IR2
v33 v34 7 7 === Questions === 8 8 9 1. **Do variables have initial values?**10 * No, a declared variable must be initialized before it is used. 9 1. **Do variables have default initial values?** 10 * No, a declared variable must be initialized before it is used. Otherwise, the behavior is undefined. 11 11 1. **How do you initialize a variable?** 12 * By assigning a value to it. For example `n=$new($int);` will assign `n` an arbitrary integer, while `n=0;` will assign the integer `0` to `n .12 * By assigning a value to it. For example `n=$new($int);` will assign `n` an arbitrary integer, while `n=0;` will assign the integer `0` to `n`. 13 13 1. **How is an array allocated?** 14 14 * An array variable `a` is declared with a decl such as `T a[];`, and then a statement such as `a=$new(T[n]);` will assign to `a` a new arbitrary array value for an array of length `n` of elements of type `T`. For heap-allocation, a pointer is declared with a decl such as `T * p;`, and a heap variable is also declared somewhere with a decl such as `$heap heap;` and then a statement such as `p = $alloc(&heap, n, T);` will add a new object to the heap and return a pointer to the first element. An `$alloc`-ed object can be deallocated with `$free(p);`. 15 1. **Is there an "array-pointer pun", as in C?** 16 * No, if you want a pointer to element 0 of an array, you have to explicitly say something like `&a[0]`. 15 17 1. **How to you translate between sequences and arrays?** 16 18 1. Can you make types values? (reification) … … 98 100 direct-declarator: 99 101 ID /* variable being declared */ 100 | direct-declarator '[' ']' /* array of ... */102 | direct-declarator '[' expr? ']' /* array of ... */ 101 103 | direct-declarator '(' type-list? ')' /* function consuming ... and returning ... */ 102 104 | '(' declarator ')' … … 104 106 type-name: ... /* same as declarator but without the ID */ 105 107 type-list: type-name (',' type-name)* ; 106 complete-type-name: ... /* same as declarator except '[' expr ']' */107 108 108 109 }}}
