Dear all,
I have this ultra simple strcture
typedef struct { uint8_t Hora; uint16_t Data1; } EEpromPaqueteDatosS;
When I do sizeof(EEpromPaqueteDatosS) it returns 4!!! But if I do the sizeof of the same structure with only one variable, in other words, with uint8_t variable it returns 1 and with uint16_t it returns 2.. but if the structure have the two variables it returns 4!!
Also if I copy the structure to a uint8_t vector I can found a strange byte in the middle.. like this:
EEpromPaqueteDatosS EEpromPaqueteDatos; uint8 data[4];
EEpromPaqueteDatos.Hora = 0x10; EEpromPaqueteDatos.Data1= 0x1020;
When I copy the structure to data, data is like 0x10, 0x??, 0x20, 0x10.. why this extra byte!!!!
Can anybody help me with this???
Thanks
You could start by helping yourself in various ways.
1) Try to take your own writing seriously, e.g. by finishing sentences with an appropriate amount of punctuation. That usually means one full stop, not half a dozen exclamation or question marks.
2) Stop blaming your tools all that easily. You need to get to grips with the idea that lots of people have been using these tools intensely before you started, so when you thing you have a problem with them, it's quite extremely unlikely that the problem really is on the tools' end of things.
3) Get some proper training, or at the very least a good textbook. You're developing a habit of jumping to conclusions based on incorrect beliefs. Wherever those beliefs come from, you need to replace that source of information by a better one.
Hi,
Hans, you are right, but, don't think my phrase was as bad as you said.. but, I will try to ask the questions better.
By the other hand memory is not important today, but, in some cases 3 or 4 more bytes when all data is 10 bytes in cost sensitive applications can be a problem.
Thanks.
"By the other hand memory is not important today, but, in some cases 3 or 4 more bytes when all data is 10 bytes in cost sensitive applications can be a problem."
You are not likely to find a chip with only 10 bytes of data, so you will then not get 30% or 40% of filler bytes. So a single struct can be used without pack.
And if you need to store 1000 structures, you have enough that it is meaningful to see it as a database and create a "read_record()" and "wrtie_record()" that handles pack/unpack.
When you have to store 10 bytes every 1 hour and the program must write data for some month, 3 or 4 bytes is very important, is the difference berween store 40 days or 70 days using a memory lime M24C128... You can place a larger memory or two memories, but, when is a cost sensitive application, you cant...
In that case, as already discussed, you should not be writing structures - you should have read() and write() functions to access the storage as a "stream"...
View all questions in Keil forum