#define Jan. 30, 2004
-
Upload
kevin-vargas -
Category
Documents
-
view
21 -
download
0
description
Transcript of #define Jan. 30, 2004
![Page 1: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/1.jpg)
15-410, S’04- 1 -
#defineJan. 30, 2004
Dave EckhardtDave Eckhardt
Bruce MaggsBruce Maggs
L09a_define
15-410“Don't make me stop the car...”
![Page 2: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/2.jpg)
15-410, S’04- 1 -
Outline
What's wrong with this picture?What's wrong with this picture?
![Page 3: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/3.jpg)
15-410, S’04- 1 -
Example 1
int scanbuf[64];
int getchar(void){ ... if (++bufindex == 64) bufindex = 0; ...}
![Page 4: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/4.jpg)
15-410, S’04- 1 -
Example 1 – Change Requirement
From: Dave EckhardtSubject: keyboard buffer size
Keyboard buffers must handle somebody placing a cat on the keyboard (the 101-key keyboard).
![Page 5: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/5.jpg)
15-410, S’04- 1 -
Option 1
int scanbuf[256];
int getchar(void){ ... if (++bufindex == 64) bufindex = 0; ...}
![Page 6: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/6.jpg)
15-410, S’04- 1 -
Option 2
int scanbuf[64];
int getchar(void){ ... if (++bufindex == 256) bufindex = 0; ...}
![Page 7: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/7.jpg)
15-410, S’04- 1 -
Option 3 – Try This At Home!!!#define KSB_SIZE 256int scanbuf[KSB_SIZE];
int getchar(void){ ... if (++bufindex == KSB_SIZE) bufindex = 0; ...}
![Page 8: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/8.jpg)
15-410, S’04- 1 -
Example 2
int scanbuf[64];
int getchar(void){ ... if (bufindex == 63) bufindex = 0; ...}
![Page 9: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/9.jpg)
15-410, S’04- 1 -
Example 2 – Truly Pernicious
How to fix How to fix halfhalf of the problem of the problem
% grep 64 *.c
Wrong Wrong twotwo ways ways– Won't find 63– Will find other 64's
![Page 10: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/10.jpg)
15-410, S’04- 1 -
Example 3
#define CENTER_X 49#define CENTER_Y 12
... set_cursor_pos(CENTER_Y, CENTER_X); ...
![Page 11: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/11.jpg)
15-410, S’04- 1 -
Example 3 – Change RequirementFrom: Dave EckhardtSubject: new screen size
We have updated the VGA hardware initialization sequence. The new screen size will be:#define CONSOLE_WIDTH 120#define CONSOLE_HEIGHT 30
![Page 12: #define Jan. 30, 2004](https://reader035.fdocuments.us/reader035/viewer/2022072112/56812d5f550346895d926bbf/html5/thumbnails/12.jpg)
15-410, S’04- 1 -
Example 4
...p->regsave[-18] |= 0x402;...
Don't make me stop the car......Don't make me stop the car......