Answer to Question #205191 in C for Tom Boyle

Question #205191

Theory questions about Compilers

1 When you are setting a bit flag (position "p"), what is the mask that you need to use and what is the operation required? What is supposed to be the mask value for reset and what is the operation? Give one example.

2.

In the buffer code, identify the problems if:

(a) You do not use a temporary variable to realloc buffer;

(b) You do not test the buffer before each function.

(c) You do not free the memory in case of error

3. In buffer, what is the purpose for setting bits EOB (end of buffer) and RLC (rellocation) and in which functions it is supposed to happen?

4. Is it possible to change buffer.h constants and typedefs that do not require modifications in the code of buffer.c? Explain and give an example.


1
Expert's answer
2021-06-11T07:05:11-0400

1) Setting the p'th bit requires a binary OR operation and a mask having all bits set to zero apart from the p'th bit that must be set to one, hence the mask value should be (1<<p). For example , Source = 10011111 p = 2

Mask value = 1<<2 =00000100

Mask | source = 10011111

Perform AND operation to reset p'th bit and bits of the mask having except the p'th bit that should be set to zero .

2)

-There will be data loss when don't realloc buffer using a temporary variable.

-There can be a buffer overflow if don't test the buffer before the start of each function.

-There can be memory leak , caches misses, and code is also not portable if don't free up the memory in case of errors.



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS