Loading ...
Sorry, an error occurred while loading the content.

Re: [blug-programming] Problem with pointers ( what else?)

Expand Messages
  • Pallav Nawani
    ... What is the difference? ... I did include stdlib.h And it is a little _test_ code, remember? ... AFAIK, p is pointing to the address of the struct pointed
    Message 1 of 12 , Aug 1, 2001
    • 0 Attachment
      On Tue, 31 Jul 2001, Subhash Chandra wrote:

      > On Tue, 31 Jul 2001, Pallav Nawani wrote:
      >
      > >
      >
      > Lets do some cleanup. It is better write above line as
      > int main(void). There is a difference between () and (void).
      >

      What is the difference?


      > > pool = (alpha *) malloc ( sizeof(alpha) * num);
      > > dead = (alpha *) malloc ( sizeof(alpha));
      > > alive = (alpha *) malloc ( sizeof(alpha));
      >
      > Rule: Never type cast the return value from malloc. Also don't
      > forget to include stdlib.h (which u did). Also should check for
      > return value NULL.

      I did include stdlib.h And it is a little _test_ code, remember?

      > > p = &(ptr->prev);
      >
      > This is the culprit. p is pointing to a member(prev) inside the node pointed
      > by ptr.

      AFAIK, p is pointing to the address of the struct pointed to by
      ptr->prev. Correct me if I am wrong.



      regards,
      Pallav.

      _______________________________________________________________________
      "Why should we subsidize intellectual curiosity?"
      -Ronald Reagan
      _________________________________________________________________
      | |
      |Pallav Nawani |
      |Fac. Z. |
      |Phone 5355503-1127. |
      |Personal Web Page: http://members.dencity.com/pallavnawani |
      |_______________________________________________________________|
    • Preetham
      hi, ... pointed ... p will have the address of ptr- prev not value of ptr- prev. it should be p=ptr- prev; preetham [Non-text portions of this message have
      Message 2 of 12 , Aug 1, 2001
      • 0 Attachment
        hi,


        > > p = &(ptr->prev);
        >
        > This is the culprit. p is pointing to a member(prev) inside the node
        pointed
        > by ptr.

        > AFAIK, p is pointing to the address of the struct pointed to by
        > ptr->prev. Correct me if I am wrong.

        p will have the address of ptr->prev not value of ptr->prev.
        it should be
        p=ptr->prev;

        preetham




        [Non-text portions of this message have been removed]
      • Ganesan Rajagopal
        ... In this case there s no difference because this is a function definition. In the case of a function *declaration* there is a difference in ANSI C. extern
        Message 3 of 12 , Aug 1, 2001
        • 0 Attachment
          >>>>> "Pallav" == Pallav Nawani <pallav@...> writes:

          > On Tue, 31 Jul 2001, Subhash Chandra wrote:
          >> On Tue, 31 Jul 2001, Pallav Nawani wrote:
          >>
          >> >
          >>
          >> Lets do some cleanup. It is better write above line as
          >> int main(void). There is a difference between () and (void).
          >>

          > What is the difference?

          In this case there's no difference because this is a function definition.
          In the case of a function *declaration* there is a difference in ANSI C.
          extern int main(void) means main takes no arguments, extern int main() means
          the prototype doesn't know what arguments main takes. Again in C++ there is
          no difference between the two since C++ *always* needs full prototypes.

          Ganesan


          --
          R. Ganesan (rganesan@...) | Ph: 91-80-5731856 Ext: 2149
          Novell India Development Center. | #include <std_disclaimer.h>
        Your message has been successfully submitted and would be delivered to recipients shortly.