I have created a dynamic typing system in C in order to create a dictionary that can contain values of different bit widths. The structure of the dynamic object is:
typedef struct
{
void* Pointer;
unsigned char Size;
} Dynamic;
I need to compare two of these Dynamics that hold A2D readings and then compare the difference against a delta value to determine if a change has occurred. One solution I have been able to come up with is to cast them to char arrays and compare them byte by byte, but that doesn't smell right. I also have an idea to make an array of function pointers based on the number of bytes (or perhaps the type) the Dynamics take up and just make a comparison function for each type supported. Can anyone suggest a different approach? It feels like I am missing something.
UPDATE:
Thanks for telling me about memcmp, but I still have the problem of how do I get the delta of the two values? From what I can tell, memcmp just returns an indicator of which value is bigger, not the difference between them.
UPDATE TO UPDATE:
Its turns out that memcmp is useless to me because the architecture I am compiling against is little endian.
If I were going to do a bignum implementation myself then ephemient feels like the right way to go, but I have decided I am just going to memcpy the values into the largest possible type (i.e. unsigned long long) that I will have to deal with and just work the math using those. I can't think of any reason why this would not work, but I recognize that I could be very wrong as C / direct memory manipulation is not my forte.