Replace invalid characters with HTML entities

— with —
’ with ’
+ with +
× with x
ç with ç
“ with “
” with ”
‘ with ‘
• with •
– with -
µ with µ
† with †
Fix C++
θ with θ
Yen symbol instead of times
Fix broken apos
Bullet again
E-circumflex
This commit is contained in:
James Gregory 2013-12-30 12:50:32 +11:00
commit 500e7f5654
353 changed files with 5091 additions and 5091 deletions

View file

@ -64,7 +64,7 @@ struct BlockHeader {
in this variable-sized block */
};
/* Structure that contains one element of the array we’ll search */
/* Structure that contains one element of the array we’ll search */
struct DataElement {
unsigned int ID; /* ID # for array entry */
unsigned int Value; /* Value of array entry */
@ -77,16 +77,16 @@ void main(void) {
struct DataElement *WorkingDataPointer;
struct BlockHeader **LastBlockPointer;
printf(”ID # for which to find average: “);
scanf(”%d”,&ampIDToFind);
printf(”ID # for which to find average: “);
scanf(”%d”,&ampIDToFind);
/* Build an array across 5 blocks, for testing */
/* Anchor the linked list to BaseArrayBlockPointer */
LastBlockPointer = &ampBaseArrayBlockPointer;
/* Create 5 blocks of varying sizes */
for (i = 1; i &lt 6; i++) {
for (i = 1; i &lt 6; i++) {
/* Try to get memory for the next block */
if ((WorkingBlockPointer =
(struct BlockHeader *) malloc(sizeof(struct BlockHeader) +
(struct BlockHeader *) malloc(sizeof(struct BlockHeader) +
sizeof(struct DataElement) * i * 10)) == NULL) {
exit(1);
}
@ -96,20 +96,20 @@ void main(void) {
*LastBlockPointer = WorkingBlockPointer;
/* Point to the first data field */
WorkingDataPointer =
(struct DataElement *) ((char *)WorkingBlockPointer +
(struct DataElement *) ((char *)WorkingBlockPointer +
sizeof(struct BlockHeader));
/* Fill the data fields with ID numbers and values */
for (j = 0; j &lt (i * 10); j++, WorkingDataPointer++) {
for (j = 0; j &lt (i * 10); j++, WorkingDataPointer++) {
WorkingDataPointer-&gtID = j;
WorkingDataPointer-&gtValue = i * 1000 + j;
WorkingDataPointer-&gtValue = i * 1000 + j;
}
/* Remember where to set link from this block to the next */
LastBlockPointer = &ampWorkingBlockPointer-&gtNextBlock;
}
/* Set the last block’s “next block” pointer to NULL to indicate
/* Set the last block’s “next block” pointer to NULL to indicate
that there are no more blocks */
WorkingBlockPointer-&gtNextBlock = NULL;
printf(”Average of all elements with ID %d: %u\n”,
printf(”Average of all elements with ID %d: %u\n”,
IDToFind, FindIDAverage(IDToFind, BaseArrayBlockPointer));
exit(0);
}
@ -135,22 +135,22 @@ unsigned int FindIDAverage(unsigned int SearchedForID,
do {
/* Point to the first DataElement entry within this block */
DataPointer =
(struct DataElement *) ((char *)BlockPointer +
(struct DataElement *) ((char *)BlockPointer +
sizeof(struct BlockHeader));
/* Search all the DataElement entries within this block
and accumulate data from all that match the desired ID */
for (WorkingBlockCount=0;
WorkingBlockCount&ltBlockPointer-&gtBlockCount;
WorkingBlockCount++, DataPointer++) {
WorkingBlockCount++, DataPointer++) {
/* If the ID matches, add in the value and increment the
match counter */
if (DataPointer-&gtID == SearchedForID) {
IDMatchCount++;
IDMatchSum += DataPointer-&gtValue;
IDMatchCount++;
IDMatchSum += DataPointer-&gtValue;
}
}
/* Point to the next block, and continue as long as that pointer
isn’t NULL */
isn’t NULL */
} while ((BlockPointer = BlockPointer-&gtNextBlock) != NULL);
/* Calculate the average of all matches */
if (IDMatchCount == 0)
@ -160,35 +160,35 @@ unsigned int FindIDAverage(unsigned int SearchedForID,
}
</PRE>
<!-- END CODE //-->
<P>The main body of Listing 8.1 constructs a linked list of memory blocks of various sizes and stores an array of structures across those blocks, as shown in Figure 8.2. The function <B>FindIDAverage</B> in Listing 8.1 searches through that array for all matches to a specified ID number and returns the average value of all such matches. <B>FindIDAverage</B> contains two nested loops, the outer one repeating once for each linked block and the inner one repeating once for each array element in each block. The inner loop&#151;the critical one&#151;is compact, containing only four statements, and should lend itself rather well to compiler optimization.</P>
<P>The main body of Listing 8.1 constructs a linked list of memory blocks of various sizes and stores an array of structures across those blocks, as shown in Figure 8.2. The function <B>FindIDAverage</B> in Listing 8.1 searches through that array for all matches to a specified ID number and returns the average value of all such matches. <B>FindIDAverage</B> contains two nested loops, the outer one repeating once for each linked block and the inner one repeating once for each array element in each block. The inner loop&mdash;the critical one&mdash;is compact, containing only four statements, and should lend itself rather well to compiler optimization.</P>
<P><A NAME="Fig2"><!-- </A><A HREF="javascript:displayWindow('images/08-02.jpg',413,265 )"> --><IMG SRC="images/08-02.jpg"><BR><!-- </A>
<BR><A HREF="javascript:displayWindow('images/08-02.jpg',413,265)"> --><FONT COLOR="#000077"><B>Figure 8.2</B></FONT></A>&nbsp;&nbsp;<I>Linked array storage format (version 1).</I>
</P>
<P>As it happens, Microsoft C/C<SMALL>&#43;&#43;</SMALL> does optimize the inner loop of <B>FindIDAverage</B> nicely. Listing 8.2 shows the code Microsoft C/C<SMALL>&#43;&#43;</SMALL> generates for the inner loop, consisting of a mere seven assembly language instructions inside the loop. The compiler is smart enough to convert the loop index variable, which counts up but is used for nothing but counting loops, into a count-down variable so that the <B>LOOP</B> instruction can be used.</P>
<P>As it happens, Microsoft C/C<SMALL>++</SMALL> does optimize the inner loop of <B>FindIDAverage</B> nicely. Listing 8.2 shows the code Microsoft C/C<SMALL>++</SMALL> generates for the inner loop, consisting of a mere seven assembly language instructions inside the loop. The compiler is smart enough to convert the loop index variable, which counts up but is used for nothing but counting loops, into a count-down variable so that the <B>LOOP</B> instruction can be used.</P>
<P><B>LISTING 8.2 L8-2.COD</B></P>
<!-- CODE //-->
<PRE>
; Code generated by Microsoft C for inner loop of FindIDAverage.
;|*** for (WorkingBlockCount=0;
;|*** WorkingBlockCount&ltBlockPointer-&gtBlockCount;
;|*** WorkingBlockCount&#43;&#43;, DataPointer&#43;&#43;) {
;|*** WorkingBlockCount++, DataPointer++) {
mov WORD PTR [bp-6],0 ;WorkingBlockCount
mov bx,WORD PTR [bp&#43;6] ;BlockPointer
cmp WORD PTR [bx&#43;2],0
mov bx,WORD PTR [bp+6] ;BlockPointer
cmp WORD PTR [bx+2],0
je $FB264
mov cx,WORD PTR [bx&#43;2]
mov cx,WORD PTR [bx+2]
add WORD PTR [bp-6],cx ;WorkingBlockCount
mov di,WORD PTR [bp-2] ;IDMatchSum
mov dx,WORD PTR [bp-4] ;IDMatchCount
$L20004:
;|*** if (DataPointer-&gtID == SearchedForID) {
mov ax,WORD PTR [si]
cmp WORD PTR [bp&#43;4],ax ;SearchedForID
cmp WORD PTR [bp+4],ax ;SearchedForID
jne $I265
;|*** IDMatchCount&#43;&#43;;
;|*** IDMatchCount++;
inc dx
;|*** IDMatchSum &#43;= DataPointer-&gtValue;
add di,WORD PTR [si&#43;2]
;|*** IDMatchSum += DataPointer-&gtValue;
add di,WORD PTR [si+2]
;|*** }
;|*** }
$I265: