Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem with structures (http://www.go4expert.com/forums/problem-with-structures-t9489/)

swordfish123 20Mar2008 20:42

Problem with structures
 
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;
mp->b_datap->db_base=buff;
return mp;
}


akshaysaidulu 23Mar2008 02:44

Re: Problem with structures
 
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.

lead.smart34 25Mar2008 15:27

Re: Problem with structures
 
i feel constant size is needed


All times are GMT +5.5. The time now is 09:12.