Moved cond.c to folder LC21
This commit is contained in:
parent
fefda4652a
commit
3ed2a4276c
18
Appendix1/Assertion/Assertions.c
Normal file
18
Appendix1/Assertion/Assertions.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 7;
|
||||
|
||||
/* Some big code in between and let's say x
|
||||
is accidentally changed to 9 */
|
||||
x = 9;
|
||||
|
||||
// Programmer assumes x to be 7 in rest of the code
|
||||
assert(x==7);
|
||||
|
||||
/* Rest of the code */
|
||||
|
||||
return 0;
|
||||
}
|
45
Appendix1/CodeBlocking/Blocking.c
Normal file
45
Appendix1/CodeBlocking/Blocking.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include<stdio.h>
|
||||
|
||||
#define BLOCKSIZE (8)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i = 0;
|
||||
int limit = 19; /* could be anything */
|
||||
int blocklimit;
|
||||
|
||||
/* The limit may not be divisible by BLOCKSIZE,
|
||||
* go as near as we can first, then tidy up.
|
||||
*/
|
||||
blocklimit = (limit / BLOCKSIZE) * BLOCKSIZE;
|
||||
/* unroll the loop in blocks of 8 */
|
||||
while( i < blocklimit )
|
||||
{
|
||||
printf("process(%d)\n", i);
|
||||
printf("process(%d)\n", i+1);
|
||||
printf("process(%d)\n", i+2);
|
||||
printf("process(%d)\n", i+3);
|
||||
printf("process(%d)\n", i+4);
|
||||
printf("process(%d)\n", i+5);
|
||||
printf("process(%d)\n", i+6);
|
||||
printf("process(%d)\n", i+7);
|
||||
|
||||
/* update the counter */
|
||||
i += 8;
|
||||
}
|
||||
if( i < limit )
|
||||
{
|
||||
/* Jump into the case at the place that will allow
|
||||
* us to finish off the appropriate number of items. */
|
||||
switch( limit - i )
|
||||
{
|
||||
case 7 : printf("process(%d)\n", i); i++;
|
||||
case 6 : printf("process(%d)\n", i); i++;
|
||||
case 5 : printf("process(%d)\n", i); i++;
|
||||
case 4 : printf("process(%d)\n", i); i++;
|
||||
case 3 : printf("process(%d)\n", i); i++;
|
||||
case 2 : printf("process(%d)\n", i); i++;
|
||||
case 1 : printf("process(%d)\n", i);
|
||||
}
|
||||
}
|
||||
}
|
11
Appendix1/DebugAssertion/DebugAssertion.c
Normal file
11
Appendix1/DebugAssertion/DebugAssertion.c
Normal file
@ -0,0 +1,11 @@
|
||||
# define NDEBUG
|
||||
#include <stdio.h>
|
||||
# include <assert.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 7;
|
||||
assert (x==5);
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user