+ 2

focus on programming... what is the problem of this code?

short *numPtr, result; void* genericPtr = numPtr; result = *genericPtr + 7;

12th Mar 2017, 4:46 PM
mahmood motallebi
mahmood motallebi - avatar
1 Odpowiedź
0
First problem is trying to invoke the + operator on a void (*genericPtr), which doesn't support it. Second problem is that even if you would statically cast it back to short to support that operation, it has been initialized with an undefined address value (because numPtr has not been initialized at all). Using a undefined zone of memory would likely yield a segmentation fault or a totally random value for your short. PS: sorry for my English.
12th Mar 2017, 11:53 PM
Arthur Van Ceulen
Arthur Van Ceulen - avatar