execv vs execvp, why just one of them require the exact file’s path?

If the program name argument contains no slashes, the execvp() function looks for the program to execute in the directories listed on your PATH environment variable. If you don’t have . (the current directory) on your PATH and you aren’t in one of the directories listed on your path, a plain name like b will not be executed, even if b is in … Read more

make: Nothing to be done for `all’

Sometimes “Nothing to be done for all” error can be caused by spaces before command in makefile rule instead of tab. Please ensure that you use tabs instead of spaces inside of your rules. instead of Please see the GNU make manual for the rule syntax description: https://www.gnu.org/software/make/manual/make.html#Rule-Syntax

Where is the C auto keyword used?

auto is a modifier like static. It defines the storage class of a variable. However, since the default for local variables is auto, you don’t normally need to manually specify it. This page lists different storage classes in C.

Cache Simulator in C

You’ve got two problems. Firstly, Scott Wales is correct about your hex2bin() function – you have a ‘x’ where you mean ‘4’. Secondly, you are not correctly counting a cache miss when you hit an invalid cache slot. You can simply handle “invalid” with exactly the same code path you use for a miss:

How to properly malloc for array of struct in C

Allocating works the same for all types. If you need to allocate an array of line structs, you do that with: In your code, you were allocating an array that had the appropriate size for line pointers, not for line structs. Also note that there is no reason to cast the return value of malloc(). Note that’s it’s better style to use: … Read more

Sign extend a nine-bit number in C

Assuming a short is 16 bits: You can do it manually: (instr & 0x1FF) | ((instr & 0x100) ? 0xFE00 : 0). This tests the sign bit (the uppermost bit you are retaining, 0x100) and sets all the bits above it if the sign bit is set. You can extend this to 5 bits by adapting the … Read more