Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday,...
-
Upload
juniper-wilkerson -
Category
Documents
-
view
216 -
download
0
description
Transcript of Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday,...
![Page 1: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/1.jpg)
Lecture 18CIS 208Wednesday, March 30, 2005
![Page 2: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/2.jpg)
Test2April 15th: Happy Tax day.
Review: Wednesday, the 13th
![Page 3: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/3.jpg)
bit fieldsstructs that hold only bit indicators
like an array of booleans
![Page 4: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/4.jpg)
bit fieldstruct tag {
type name1: length;type name2: length;. . .type nameN: length;
}variable_list;
![Page 5: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/5.jpg)
bit field typesmust be either int, unsigned, or signed.
length is the number of bits assigned to that label
total size can’t be larger that 1 word
![Page 6: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/6.jpg)
examplestruct status_type{
unsigned send : 2; //2 bits wideunsigned rec : 3; //3 bits wideunsigned p1 : 1;unsigned p2 : 1;} status ;
![Page 7: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/7.jpg)
accessingonce again, . or ->
same rules, blah blah blah.
status.rec = 4; status.p2 = 1; if (status.p1) {…}
![Page 8: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/8.jpg)
run time errorsattempting to give a value outside of range.
status.send = 5;status.rec = -1;
![Page 9: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/9.jpg)
can mix and matchcombine bit fields with other structs
struct emp {struct adr address;float pay;unsigned lay_off : 1;unsigned hourly: 1;unsigned deductions: 3;
};
![Page 10: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/10.jpg)
restrictionssingle bits variables must be unsigned.
Can’t find address of bit field variablebit field variables can’t be arrayed.
![Page 11: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/11.jpg)
Uses:Limited storage (can store several Booleans in just one byte)
some devices only transmit info encoded into bits.
![Page 12: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/12.jpg)
int ungetC(char ch, FILE *stream)
returns a character to an input stream. Can’t unget EOF
Will be the next character read from stream.
returns value equal to ch if successful, else EOF
one character pushback is guaranteed. Some compilers will accept more.
![Page 13: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/13.jpg)
example#include <stdio.h>void read_word(FILE *fp, char *token) {
while (isalpha(*token = getc(fp))) token++;ungetc(fp, *token);
}
read_word(in, “count/10”)?????
![Page 14: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/14.jpg)
Conditional Compilation Directives
Might not want some code compiled.
These preprocessor commands tell compiler to skip over section of code.
Allow for easy porting.
![Page 15: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/15.jpg)
#if #else #elif #endif#if constant_expression
statement sequence#endif
if the expression, then the statement sequence is compiled.
expression must be constant, no variables.use Macros. Can be nested
![Page 16: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/16.jpg)
#if #else #elif #endif#include <stdio.h>#define MAX 10;void main(void) {
#if MAX >99printf(“compiled for array greater than 99\n”);#elseprintf(“compiled for small array\n”);#endif
}
![Page 17: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/17.jpg)
#elif == else if#define US 0#define ENGLAND 1#define FRANCE 2#define ACTIVE_COUNTRY US
#if ACTIVE_COUNTRY == USchar currency[] = “dollar”;
#elif ACTIVE_COUNTRY == ENGLANDchar currency[] = “pound”;
#elsechar currency[] = “franc”;
#endif
![Page 18: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/18.jpg)
#ifdef #ifndef#ifdef macro_name
statement sequence#endifTrue if macro_name is defined.
#ifndef macro_namestatement sequence
#endifTrue if macro_name is undefined.
![Page 19: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/19.jpg)
#ifdefmay use #elsecan’t use #elif
void main(void){#ifdef FRED
printf(“HI Fred”);#else
printf(“hi anyone”);#endif#ifndef RALPH
printf(“RALPH not defined”);#endif
}
![Page 20: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/20.jpg)
#undefundefined a macro. after command, macro name is useless.
can be re-defined anytime afterwards.
![Page 21: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/21.jpg)
#linesets the current line number
#include <stdio.h>#line 100 //reset the line countervoid main(void) { //line 100
printf(“%d”,__LINE__); //line 101}
prints out 101.
![Page 22: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/22.jpg)
pre-defined macros__LINE__ :: current line number (int)__FILE__ :: current file name (string)__DATE__ :: date month/day/year (string)__TIME__ :: Time, hour:minute:second
(string)__STDC__ :: constant decimal 1
![Page 23: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/23.jpg)
comments/*This is C-Style */
//This is C++ style.//Might not work with all compilers.
![Page 24: Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.](https://reader035.fdocuments.net/reader035/viewer/2022062504/5a4d1b677f8b9ab0599b1485/html5/thumbnails/24.jpg)
C++Starts on Friday
Won’t be on test 2