Title: Theory / Unimportant / CS / Programming / C Harbison Steele{ / 08 Statements+8;
Tags: FromInstruction computer_to_instruction hasNotNewEffectReturnsMeaning récupéré seen_description some_instruction syntactical_sugar

Instruction: switch (foo) {
buz0
case bar1 :
buz1
...
case barn:
buzn
default:
buzn+1
}
Page: 274
Effect: consider the term foo
let i the least integer such that foo's value is bari, or n+1 if no such that i exists
Execute buzi, ..., buzn+1 (until there is a breaking statement)
Similar to:
var tmp= foo;
if (tmp==bar_1) goto bar_1;
...
else if (tmp==bar_n) goto bar_n;
else goto default;
bar_1 :
 buz_1
   ...
barn:
  buz_n
default:
 buz_n+1
Assuming the bar_i and default does not belong to an inner switch statement
Language: C
Chapter: 8
Section: 7
Assuming: each bar_i constant
Typ: expression must be number or string

Instruction: foo;
Page: 261
Effect: effect of foo
Language: C
Chapter: 8
Section: 2
Returns: void
Variables: foo an expression

Smaller0: foo has no side effect
Greater0: foo may be not evaluated
Page: 208
Chapter: 8
Section: 1
Variables: foo an expression
Smaller1: foo's value is discarded

Instruction: foo: bar
Page: 261, 280
Effect: assign the label foo to the statement bar
Language: C
Chapter: 8
Section: 4
Name: labeled-statement

Question: How to attach label to declarations ?
Answer: Assign it to a null statement before the declaration
Page: 261
Chapter: 8
Section: 4

Instruction: {
foo_1
...
foo_n
}
Page: 261
Effect: the effect of the foo_i in this order
Language: C
Chapter: 8
Section: 4
Intuition: Compound statement

Name: Block level identifier
Definition: An identifier whose declaration is block-level
Page: 261
Chapter: 8
Section: 4.1

Name: Block level declaration
Definition: A declaration within a block
Page: 261
Chapter: 8
Section: 4.1

Question: The default storage class is
Answer: extern for function type.
Page: 261
Chapter: 8
Section: 4.1
Context: C
Answer2: Auto otherwise

Smaller0: i storage class is explicitly auto
Greater0: i's storage class is auto
Page: 261
Chapter: 8
Section: 4.1
Variables: i an identifier
Smaller to greater: iff
Smaller2: i is not specified
Suffix Smaller: )
Smaller3: i does not referes to a function
Connect Smaller1: or (
Connect Smaller2: and

Smaller0: i storage class is explicitly extern
Greater0: i's storage class is extern
Page: 261
Chapter: 8
Section: 4.1
Variables: i an identifier
Smaller to greater: iff
Smaller2: i storage class is not explicited
Smaller3: i is a function)
Connect Smaller1: or (
Connect Smaller2: and

Smaller0: i storage class is extern
Greater0: no storage is allocated for i
Page: 261
Chapter: 8
Section: 4.1
Variables: i an identifier
Greater1: no initialization expression is permitted for i

Smaller0: i storage class is auto or register
Greater0: i is allocated with undefined value when the block is entered, and deallocated when the block is exited
Page: 261
Chapter: 8
Section: 4.1
Variables: i an identifier
Smaller1: i is not a variable length array

Smaller0: i is a variable length array
Greater0: at initialization
Page: 261
Chapter: 8
Section: 4.1
Variables: i an identifier
Prefix Greater: i is allocated
Greater1: leaving the block or when there is a jump before the declaration
Connect Greater0: and i is deallocated
Greater2: it is illegal to jump in the array's scope

Smaller0: i is static
Greater0: when program start
Page: 261
Chapter: 8
Section: 4.1
Variables: i an identifier
Prefix Greater: i is allocated
Greater1: never
Connect Greater0: and i is deallocated
Greater2: only when program start. Initialization does not occur again the next time.
Connect Greater1: and i is initialized
Greater3: the initialization value must be a constant

Instruction: if (foo) bar
Page: 264
Effect: evaluates foo. If foo is non-zero, evaluate bar
Language: C
Chapter: 8
Section: 5
Name: if-statement

Instruction: if (foo) bar else plop
Page: 264
Effect: evaluates foo. If foo is non-zero, evaluate bar. Otherwise, evaluates plop
Language: C
Chapter: 8
Section: 5
Name: if-else-statement

Name: conditional-statement
Definition: if-else-statement and if-statement
Page: 264
Chapter: 8
Section: 5

Name: Multiway conditional statement
Definition: A sequence of if, else if, and potentially an else
Page: 264
Chapter: 8
Section: 5.1

Question: In case of ambiguity, an else is linked to which if ?
Answer: The innermost one
Page: 265
Chapter: 8
Section: 5.2
Context: C

Name: Iterative statement
Definition: While-statement, do-statement and for-statement
Page: 266
Chapter: 8
Section: 5.2

Name: The body of l
Definition: plop
Page: 266
Chapter: 8
Section: 5.2
Variables: l a loop :
for (foo){
plop
}

Instruction: while (foo) bar
Page: 266
Effect: Evaluates foo. If it non-zero, evaluates bar and start again from start.
init: if (!foo) goto end;
bar;
goto init;
end;
Language: C
Chapter: 8
Section: 6.1
Name: while-statement

Instruction: do bar while (foo);
Page: 266
Effect: Evaluates bar. Evaluates foo. If it non-zero, start again from start
label: bar
if (foo) goto label
Language: C
Chapter: 8
Section: 6.2
Name: do-statement

Name: initial-clause
Definition: either expression or declaration
Page: 269
Chapter: 8
Section: 6.3

Name: for-expression
Definition: (foo;bar;plop) when it occurs after a for
Page: 269
Chapter: 8
Section: 6.3

Instruction: for (foo;bar;plop) miam
Page: 269
Effect: Similar to
foo;
while (plop) {miam
bar;
}
Language: C
Chapter: 8
Section: 6.3
Name: for-statement

Instruction: for (;;) foo
or
while(1)foo
Page: 270
Effect: Execute infinitely often foo
Language: C
Chapter: 8
Section: 6.4
Name: do forever loop

Name: case-label
Definition: case constant-expression
Page: 270
Chapter: 8
Section: 6.4

Name: default-label
Definition: default
Page: 270
Chapter: 8
Section: 6.4
Context: C

Name: The body of s
Definition: buz_0
case bar_1 :
buz_1
...
case bar_n:
buz_n
default:
_buz_n+1
Page: 270
Chapter: 8
Section: 6.4
Variables: s a switch statement
switch (foo) {
buz_0
case bar_1 :
buz_1
...
case bar_n:
buz_n
default:
_buz_n+1
}
Context: C

Name: Drop through
Definition: In a switch statement, the fact that the execution of one case does not stop when the next case/default is written
Page: 276
Chapter: 8
Section: 6.4
Context: C switch

Instruction: break;
Page: 277
Effect: go to the end of the enclosing loop or case block
Language: C
Context: switch
Chapter: 8

Instruction: continue;
Page: 277
Effect: end this occurence of the loop,
Language: C
Context: switch
Chapter: 8

Instruction: return foo;
Page: 277
Effect: End the function, sending the optional value foo to the caller
Language: C
Context: switch
Chapter: 8
Name: return-statement

Question: Which value is returned by a function when no return statement is executed
Answer: undefined if the type is non void
Page: 277
Chapter: 8
Context: C

Question: What is the best use of goto
Answer: Avoid them
Page: 280
Chapter: 8
Section: 10
Context: C
Answer2: Do not jump between then and else
Answer3: use break, continue or return if possible

Instruction: ;
Page: 280
Effect: None and no value
Language: C
Chapter: 8
Section: 11
Name: null statement

Instruction: goto foo
Page: 280-282
Effect: jump to instruction labeled by foo
Language: C
Chapter: 8
Section: 10
Assuming: In C++, if this would create a variable, which should be initialized at creation, then this goto is forbidden