Content deleted Content added
Stevebroshar (talk | contribs) →C language: Split C section into C-stuff and non-C-stuff |
Stevebroshar (talk | contribs) →Examples of control tables: Normalize structure->add general section |
||
Line 92:
The examples below have been chosen partly to illustrate potential performance gains that may not only ''compensate'' significantly for the additional tier of abstraction, but also ''improve'' upon – what otherwise might have been – less efficient, less maintainable and lengthier code. Although the examples given are for a 'low level' assembly language and for the [[C (language)|C language]], it can be seen, in both cases, that very few lines of code are required to implement the control table approach and yet can achieve very significant [[constant time]] performance improvements, reduce repetitive source coding and aid clarity, as compared with [[verbose]] conventional program language constructs. See also the [[Control table#Quotations|quotations]] by [[Donald Knuth]], concerning tables and the efficiency of [[multiway branch]]ing in this article.
==Examples
===General===
▲"CT1" is an example of a control table that is a simple [[lookup table]]. The first column represents the input value to be tested (by an implied 'IF input1 = x') and, if TRUE, the corresponding 2nd column (the 'action') contains a subroutine address to perform by a [[System call|call]] (or [[goto|jump]] to – similar to a [[Switch statement|SWITCH]] statement). It is, in effect, a [[multiway branch]] with return (a form of "[[dynamic dispatch]]"). The last entry is the default case where no match is found.
:{| class="wikitable"
Line 111 ⟶ 110:
| {{mono|?}} || → ||Default
|}
=== Assembly language ===
|