ECE485 RTOS Group 1
What is the size (the number of bytes) of myvar signed char myvar;
1 byte
What is the size (the number of bytes) of myvar Assuming that the Keil compiler will assign a 32-bit integer for each enumerate value (RED, BLUE or GREEN) typedef enum color {RED=0, BLUE=1,GREEN=2 } color_type; color_type myvar = BLUE;
4 bytes
What is the size (the number of bytes) of myvar Typedef struct os_tcb { unsigned char *px; struct os_tcb *pt; char dir; char p[5];} OS_TCB; OS_TCB myvar;
4 bytes 4 bytes 1 byte 6 bytes 15 bytes
What is the size (the number of bytes) of myvar signed char *myvar;
4 bytes (pointer)
What is wrong with this C macro definition? (3 points) #define MUL(a,b) a*b
Order of operations is ambiguous and may not result in the answer the programmer is actually wanting.
What is wrong with this C macro definition? (3 points) #define MIN(a,b) ((a) <(b))? (a): (b)) better ((a++)<(b++))?(a++):(b++) Hint: considering this example, int a=1, b=2; printf("%d\n",MIN(a,b)); printf("%d\n",MIN(a++,b++));
This macro could result in double evaluation. Inline would be better.
Write one line C code to define the data type of int8_t.
Typedef signed char int8_t;
Please list the advantage(s) of using the defined datatype uint8_t instead of char?
Using uint8_t may be a distinct extended integer type and doesn't need the same representation as char. Uint8_t can also more easily fit with aliasing of data types. Only have to change 1 header file.
unsigned char xyz; Set the variable xyz bit 4, bit 5 and bit 6 LOW without modifying the other bits. Use only one line C-code.
XYZ = XYZ &~(1<<4 | 1<<5 | 1<<6);
unsigned char xyz; Set the variable xyz bit 6 HIGH without modifying the other bits, using one C-code only.
XYZ = XYZ | (1<<6);
unsigned char xyz; Set the variable xyz bit 7, 6, 5 and 4 as the value 0101 (binary) without modifying other bits, using only one line C-code.
XYZ=(( XYZ & ~ ( 1 << 4 | 1 << 5 | 1 << 6 | 1 << 7 ) | ( 1<< 6 | 1 << 4 );
What is the size (the number of bytes) of myvar char myvar[] = "555555";
allocate 7 bytes
Below is a sample of a C file foo.c (5 points) uint32_t myvar1 = 0; static uint8_t myvar2; extern int16_t myvar3; extern func1(uint8_t c); static func2(uint8_t c) { } void func3(uint8_t c) { } Please describe the scopes of variables myvar1, myvar2, myvar3 and functions func1(), func2(), func3().
myvar1: global variable (can be accessed from anywhere) myvar2: local static variable(can't be accessed from outside file) myvar3: declared in separate file func1: declared in separate file func2: local static function (can't be accessed from outside file) func3: function that can be accessed from anywhere but doesn't return a value