#define ALLOW_INSTRUCTOR_CODE /*************************************************************************** *************************************************************************** ****** BEFORE BEGINNING OR TURNING IN THIS EXERCISE IT IS EXTREMELY ****** ****** IMPORTANT THAT YOU READ, FULLY UNDERSTAND, AND ADHERE TO THE ****** ****** REQUIREMENTS STATED IN THE DOCUMENT TITLED, "ASSIGNMENT ****** ****** SUBMISSION REQUIREMENTS", DOWNLOADABLE FROM THE COURSE WEB ****** ****** SITE. ****** *************************************************************************** **************************************************************************/ /*************************************************************************** ************* C/C++ Programming 2: Assignment 2 - Exercise 1 ************* ********* BEGIN EXERCISE REQUIREMENT - THIS MUST BE A "C" PROGRAM ********* *************************************************************************** (1 point) The number of bits in type char (1 char = 1 byte) is an implementation-dependent value greater than or equal to 8 while the number of bits in type int is an implementation-dependent value greater than or equal to 16. Write function CountIntBitsF and macro CountBitsM: CountIntBitsF syntax: int CountIntBitsF(void); Parameters: none Synopsis: Determines the number of bits in data type int on any machine on which it is run. Return: the number of bits in data type int CountBitsM syntax: int CountBitsM(type); Parameters: type - any data type (literally: int, float, double, etc.), or any non-void expression (24, x, printf("Hello"), etc.) Synopsis: Determines the number of bits in the data type of on any machine on which it is run. Hint - This is an extremely trivial macro. Return: the number of bits in the data type of CountIntBitsF and CountBitsM: * Shall not assume a char/byte contains 8 bits (or any other value) * Shall not call any function * Shall not use any external variables * Shall not perform any right-shifts * Shall not display anything CountIntBitsF: * Shall not use any macro CountBitsM: * Shall not declare any variables * May use a macro from *************************************************************************** ************************ END EXERCISE REQUIREMENT ************************* **************************************************************************/ /*************************************************************************** * BEFORE PRINTING THIS ASSIGNMENT TO TURN IN, DELETE THIS COMMENT AND * EVERYTHING ABOVE IT. **************************************************************************/ /* * TODO: * REPLACE THIS COMMENT WITH YOUR TITLE BLOCK. */ /* * TODO: * REPLACE THIS COMMENT WITH YOUR C CODE, PLUS ANYTHING NECESSARY TO * SUPPORT MY TEST CODE BELOW. DO NOT INCLUDE ANY UNNEEDED HEADER FILES! */ /*************************************************************************** * BEFORE PRINTING THIS ASSIGNMENT TO TURN IN, DELETE THIS COMMENT AND * EVERYTHING BELOW IT. **************************************************************************/ /* ***** Change nothing below this comment without instructor permission. **** * Everything that follows was written to help test/verify your code. You * do not need to understand the details of my code to write yours! */ #ifdef ALLOW_INSTRUCTOR_CODE int main(void) { /* Ignore "unreferenced variable" warnings for the 4 declarations. */ char cArray[25]; double dArray[25]; long double xyz; typedef struct test {long double x; float y; struct test *p;} TEST; /* Test the function version. */ printf("Implementation-dependent bit widths:\n\n"); printf(" From CountIntBitsF:\n"); printf(" Type 'int' -> %d\n\n", CountIntBitsF()); /* Test the macro version. */ printf(" From CountBitsM:\n"); printf(" Type 'char' -> %d\n", CountBitsM(char)); printf(" Type 'short' -> %d\n", CountBitsM(short)); printf(" Type 'int' -> %d\n", CountBitsM(int)); printf(" Type 'long' -> %d\n", CountBitsM(long)); printf(" Type 'float' -> %d\n", CountBitsM(float)); printf(" Type 'double' -> %d\n", CountBitsM(double)); printf(" Type 'long double' -> %d\n", CountBitsM(long double)); printf("\n"); /*lint -e719 */ printf(" printf return -> %d\n", CountBitsM(printf(""))); /*lint +e719 */ printf(" 'A' -> %d\n", CountBitsM('A')); printf(" 2000000+8000000 -> %d\n", CountBitsM(2000000 + 8000000)); printf(" xyz -> %d\n", CountBitsM(xyz)); printf(" cArray -> %d\n", CountBitsM(cArray)); printf(" dArray -> %d\n", CountBitsM(dArray)); printf(" TEST -> %d\n", CountBitsM(TEST)); printf("\n"); return EXIT_SUCCESS; /*lint -e550 -e754 */ } #endif