-
Transaction_history
Hi friends........
I joined in company..........
Here i am in the embedded department(software).......
I need sum help regarding coding...
typedef struct stTrans
{
char cOpID;
unsigned char aucTransData[20000];
}__attribute__((packed)) TRANSACTION_HISTORY;
while developping a server programm.......in that like this a structure has been defined......
But I did not understand.....why They defined like this at the last line......That is as typedef __attribute__((packed)) TRANSACTION_HISTORY;
can anybody help me out plz...........
thanks and regards
k.venkata ramana rao
-
Re: Transaction_history
Well, this [QUOTE]__attribute__((packed))[/QUOTE] tells the compiler not to pad the memory. Basically this is used to maintain portability of the code.
Usually compilers will store the variables in memory chunks of 16buts or 32 bits or 64 bits depending on the compiler. Now let us say that we define an string of length = 7, like
char str='kalayam' ,
how would the compiler allocate the memory? Assume that the start address is 0. Then
0 - k
1 - a
2 - l
2 - a
3 - y
4 - a
5 - m
6 - Paddes byte
To make it 32 bits, the compiler will pad a byte, which causes undesirable effects in systems as critical as embedded systems. Hence we tell the compiler not to pad any bytes.
Here are some reference links for you.
[URL="http://www.freescale.com/files/soft_dev_tools/doc/white_paper/CWPORTINGWP.pdf"]A compiler Book[/URL]
[URL="http://books.google.com/books?id=4DJG7AY1SkwC&pg=RA1-PA295&lpg=RA1-PA295&dq=_attribute__+packed&source=web&ots=WCGtGvzinE&sig=YPYqT7t6lvQwpw7aGXW-vCgOqSg"]From Google Books....[/URL]
Hope that helps....
Cheers!
Kalayama