I try to make a subfunction which can write any data formation (int, float etc) into eeprom so that one doesn't need to worry about low level operation such as creating union data formats when they call this subfunction.
As a result, I create a union data format in this subfunction, but the legnth of this union data can't be a int variable. cause when I do this variable.B[lengthOfData], it shows an error, saying lengthOfData is not an integral constant-expression. When I replace the lengthOfData with 2, it works fine.
I try to learn to write something usefull, and also contribute some day, instead of just include libs made by others, so I guess it is not reinventing the wheel...
joedodo:
I try to learn to write something usefull, and also contribute some day, instead of just include libs made by others, so I guess it is not reinventing the wheel…
joedodo:
I try to learn to write something usefull, and also contribute some day, instead of just include libs made by others, so I guess it is not reinventing the wheel...
It IS re-inventing the wheel, and replacing it with something inferior. A union is NOT the right solution.
I doubt that an inexperienced programmer would make that connection with Reply #5. Personally I assumed that @RayLivingston had some other solution in mind.
Robin2:
I doubt that an inexperienced programmer would make that connection with Reply #5. Personally I assumed that @RayLivingston had some other solution in mind.
...R
Nope. Get() and Put() are as good as it gets, do not need "improvement", work with any data type, don't waste resources on unions, and won't create processor-dependant problems unions will.
RayLivingston:
Nope. Get() and Put() are as good as it gets,
My comment was not about the solution - I know nothing about the matter.
I was commenting in Reply #5 about the style of your Reply which seems to me to leave the OP dangling in mid air when it might have said " .... A union is NOT the right solution - see Reply #1"