Hello, this is my first post on these forums but I have been a lurker over the years as a student and professional programmer...
Anyway, here is my dilemma, thanks in advance for taking the time to help:
I want to have a static length list of pointers to different data types (there are three at the moment with plans for expansion in the future). But I also need to retain the size of the data at the pointer location because I will have to read and write to it. As far as I understand, this means that (void *) is out unless I do something like below.
The purpose of this code is to generate a list of pointers to variables that range from 16 to 64 bits and will be read from/written to via a serial port 16-bits at a time. I need to retain the size of the data so that I know when to stop reading and writing.
Here is my code snippet currently (I want it to be better!):
Code:
typedef struct{ void * VarLoc;
int VarSize;
}DebugStruct;
DebugStruct DebugVars[] = {
{(void *)&varA,sizeof(varA)},
{(void *)&varB,sizeof(varB)},
{(void *)&sweep_run,sizeof(sweep_run)}
};
I want to be able to easily add another entry, re-compile and download to my DSP.
Here are two general guidelines:- Memory conscious (This code will be going on a <1USD part, memory space is limited)
- It has to be as easy to modify as possible. I want to make a list of variables that will be commonly needed via the serial port during implementation, but I will probably forget some and need to make some last minute changes in the lab. I can not fumble around with clumsy implementations (like above :P).
An ideal solution would be to use only a pointer and determine the length of the data when needed.
Finally, I tried using a UNION of the different pointer types but my compiler initializes the value to the type listed first in the UNION declaration. I am not smart enough to circumvent that and simultaneously comply with the guidelines above.
I do not need production level code in a reply, a quick snippet, suggestions, criticism or a link to some resources would be fine.
Thanks for your time.