void *p problem; - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

void *p problem;


hi, I have one question about void *p;

void *p;
struct block *bh;
struct disk *docs;

bh=(struct block *)p;
docs=(struct disk *) ( (unsigned long)p+sizeof(struct block));

my question is that which address p points to now?

Does p point to the address (p+sizeof(struct block)) ?

please help me,

Thanks a million


Comments

  • anthrax11anthrax11 Posts: 511Member
    p doesn't point to anything, because it is uninitialized.
    Maybe you have a typo somewhere?
  • shizhihongshizhihong Posts: 3Member

    int A(void *p,struct word_cache *wc,int index)
    {
    struct block *bh;
    struct disk *docs;

    ....
    .....
    ....

    bh=(struct block *)p; //cast the void * to struct block
    docs=(struct disk *) ( (unsigned long)p+sizeof(struct block));
    //calculate the memory location of the struct disk:
    //then cast it to struct disk.

    ....
    .....

    }

    we pass an parameter void *buf to the first parameter of A();
    So, in this case does p point to different address (+sizeof(struct block))
    or it points to the original address ?

    please help me, thanks


  • anthrax11anthrax11 Posts: 511Member
    Sorry, I still can't understand what you mean.

    The value of p is what you pass to the A function.
    p+sizeof(struct block) is a combined address that points to whatever is sizeof(struct block) bytes after what p points to, but this addition operation doesn't change the value of p itself.
  • shizhihongshizhihong Posts: 3Member
    Thank you.
    I've already understood it.

    thanks a million
Sign In or Register to comment.