Download presentation
Presentation is loading. Please wait.
1
Using enum
2
Define some system values
//Define some states for an I/O device, such as a disk drive // O/S needs to test to see what state it is in Enum IO_status //These are the ONLY values allowed {UnInitialized, Initialized, Ready, Started, Inprogress, Completed, Busy, Error, Sense_data_pending }
3
Now use those values int IO_test(const IO_Status disk_state) // only enum values are legal { // cannot assign an arbitrary value to a name switch(disk_state) { case UnInitialized: Initialize_disk(disk_id); return(0); case Busy: return(-1); case Sense_data_pending: Get_sense_date(disk_id); //Put it where caller can get it Return(sense_error); // etc. Default: return (-1); }
4
Issues No type-checking (can be signed /unsigned)
Cannot print the "name" of the value ("Busy") cout<<busy; // yields an integer a table lookup would be needed Alternative: use a string. Can't use a switch Case sensitivity Compare is slower Uses more memory Can print the name
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.