1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem with structures

Discussion in 'C' started by swordfish123, Mar 20, 2008.

  1. swordfish123

    swordfish123 New Member

    Joined:
    Mar 20, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi guys,

    i am writing a code using mblk/dblk. I have implemented my own allocb function. Hopefully it is right.

    When i try to assign the buff to the dblk_t structure element (the statement shown in bold) i get an error. If i comment out that line everything works fine.
    Am i doing something wrong.
    Can someone help me assign the buff to db_base of the struct dblk_t



    Code:
     struct dblk_t {
        struct dblk_t *db_freep;           /* internal use                     */
        unsigned char *db_base;             /* first byte of buffer             */
        unsigned char *db_lim;              /* last byte +1 of buffer           */
        unsigned char *db_vbase;            /* first byte of system buffer      */
        int (*db_cb)();                     /* callback routine                 */
        unsigned long int db_size;
        unsigned char db_ref;               /* count of  to this block  */
        unsigned char db_type;              /* message type                     */
        unsigned char db_class;             /* internal use                     */
        unsigned char db_id;
        };
    
     struct mblk_t {
        struct mblk_t *b_next;             /* next message on queue            */
        struct mblk_t *b_prev;             /* previous message on queue        */
        struct mblk_t *b_cont;             /* next message block of message    */
        unsigned char *b_rptr;              /* first unread data byte in message */
        unsigned char *b_wptr;              /* first unwritten data byte inbuffer*/
        struct dblk_t *b_datap;                    /* data block            */
        };
    
    
    
    struct mblk_t* allocb(int size)     
    {                                    
    
    struct mblk_t *mp;
    struct mblk_t mp1;
    
    mp=&mp1;
    
    unsigned char buff[size];
    mp->b_rptr=buff;
    mp->b_wptr=buff;
    [B][SIZE="5"]mp->b_datap->db_base=buff;[/SIZE][/B]
    return mp;
    }
    
    
     
  2. akshaysaidulu

    akshaysaidulu New Member

    Joined:
    Mar 22, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    problem is that
    struct mblk_t* allocb(int size)
    {

    struct mblk_t *mp;
    struct mblk_t mp1;

    mp=&mp1;

    unsigned char buff[size];

    size should be const.
     
  3. lead.smart34

    lead.smart34 New Member

    Joined:
    Feb 14, 2008
    Messages:
    77
    Likes Received:
    0
    Trophy Points:
    0
    i feel constant size is needed
     

Share This Page