Results 1 to 2 of 2

Thread: Transaction_history

  1. #1
    Junior Member
    Join Date
    Sep 2006
    Answers
    1

    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


  2. #2
    Expert Member
    Join Date
    Sep 2006
    Answers
    477

    Re: Transaction_history

    Well, this
    __attribute__((packed))
    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.
    A compiler Book

    From Google Books....

    Hope that helps....

    Cheers!
    Kalayama

    Last edited by kalayama; 03-01-2007 at 06:39 AM. Reason: One of the links went missing
    [COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

    Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact