Interview Question
Software ArchitectsCountry: United States
Interview Type: In-Person
Those are types are not the same, and it a mistake to try to place void pointer into unsigned int .if you planning to build a software that need to run on set of platforms or different arch.
for example on LP64 arch the sizeof(void*) will be 8 and sizeof(unsigned int) will be 4
on ILP32 the size will be the same,,,
First, we all know what is generic implementation is. Probably in C++ we use template.
In plain C and most embedded technologies ,we use void pointer for generic implementation in C which is basically used to type cast to any other type of valid pointer.
So. what if we use unsigned int to do similar kind of generic implementation.
Firstly can it be done ?? Well we have certain API's in Win 32 library which use unsigned int and share the address space to make the generic behavior of API's.
So, typically we can make an API generic by void pointer and unsigned int (As we can see in numeric examples).. So the question here is what causes the developer to prefer one over other and why?
Whats the advantage and disadvantages of one over other ??
NOTE :- Now for those who has given lot of idiotic comments as I can see.. need to understand the question properly.. Hope it will help you guys to open your eyes before puttinf any more stupid comments.. :)
I think void pointer can be cast to any other type of pointers, like that if you want to implement a stack in c code to store any type of data,
struct stack_s{
int size;
void **table;
int top;
} if you use int* then you can only store int datas, but if you use void* you can store any type of datas.
then take a look at unsigned int, do you think if we balance the size of a vector or other thing will use negative, or a vector's size is negative, so it obviously tells us that unsigned int can represent the size.
Well the question is not abt the void POINTER and int POINTER (there are hell lot of diff in this case).. The question is about void POINTER and unsigned int. Think deeply...
A very deep question. A deeply stupid question that is. Especially if targetted towards "Software Architects".
Did you create this hprem?
Well.. than U are jst show what is your level of deep understanding on the subject. I guess U need to first understand before wasting your unnecessary effort to put the comments..
Anyways thanks for highlight how Stupid and coward are U to put comment without name..
Their size might not always be the same.
- Varun March 19, 2013Typically on x86 arch, we have sizeof(pointer) and sizeof(unsigned int) same, but this might not be true always on all machine.