51) How can you define a structure with bit field members?
char c1 : 3;
char c2 : 4;
char c3 : 1;
Here c1, c2 and c3 are members of a structure with width 3, 4, and 1 bit respectively. The ':' indicates that they are bit fields and the following numbers indicates the width in bits.
int GetFieldValue(int byte, int field )
byte = byte >> field;
byte = byte & 0x01;
The byte is right shifted exactly n times where n is same as the field value. That way, our intended value ends up in the 0th bit position. "Bitwise And" with 1 can get the intended value. The function then returns the intended value.
53) Which parameters decide the size of data type for a processor ?
Actually, compiler is the one responsible for size of the data type. But it is true as long as OS allows that. If it is not allowable by OS, OS can force the size.
54) What is job of preprocessor, compiler, assembler and linker ?
The preprocessor commands are processed and expanded by the preprocessor before actual compilation. After preprocessing, the compiler takes the output of the preprocessor and the source code, and generates assembly code. Once compiler completes its work, the assembler takes the assembly code and produces an assembly listing with offsets and generate object files.
The linker combines object files or libraries and produces a single executable file. It also resolves references to external symbols, assigns final addresses to functions and variables, and revises code and data to reflect new addresses.
55) What is the difference between static linking and dynamic linking ?
In static linking, all the library modules used in the program are placed in the final executable file making it larger in size. This is done by the linker. If the modules used in the program are modified after linking, then re-compilation is needed. The advantage of static linking is that the modules are present in an executable file. We don't want to worry about compatibility issues.
In case of dynamic linking, only the names of the module used are present in the executable file and the actual linking is done at run time when the program and the library modules both are present in the memory. That is why, the executables are smaller in size. Modification of the library modules used does not force re-compilation. But dynamic linking may face compatibility issues with the library modules used.
56) What is the purpose of the preprocessor directive #error?
Preprocessor error is used to throw a error message during compile time. We can check the sanity of the make file and using debug options given below
#error Include DEBUG or RELEASE in the makefile
57) On a certain project it is required to set an integer variable at the absolute address 0x67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task.
This can be achieved by the following code fragment:
ptr = (int *)0x67a9;
*ptr = 0xaa55;
58) Significance of watchdog timer in Embedded Systems.
The watchdog timer is a timing device with a predefined time interval. During that interval, some event may occur or else the device generates a time out signal. It is used to reset to the original state whenever some inappropriate events take place which can result in system malfunction. It is usually operated by counter devices.
59) Why ++n executes faster than n+1?
The expression ++n requires a single machine instruction such as INR to carry out the increment operation. In case of n+1, apart from INR, other instructions are required to load the value of n. That is why ++n is faster.
60) What is wild pointer?
A pointer that is not initialized to any valid address or NULL is considered as wild pointer. Consider the following code fragment -
*p = 20;
Here p is not initialized to any valid address and still we are trying to access the address. The p will get any garbage location and the next statement will corrupt that memory location.