linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: km <km@mrna.tn.nic.in>
To: Luciano Moreira - igLnx <lucianolnx@ig.com.br>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: pointer notation
Date: Tue, 28 Oct 2003 23:16:05 +0530	[thread overview]
Message-ID: <20031028174605.GA5517@mrna.tn.nic.in> (raw)
In-Reply-To: <3F9E5A41.40204@ig.com.br>

Hi all,
i should have posted the snippet before itself to be clear, which i am doing now.

It is from a double-linked list snippet as follows : 
----------------CODE START---------------------------------------
#include<stdio.h>
#include<stdlib.h>
struct node
{
int content;
struct node *next;
struct node *previous;
};
/* prototype declaration */
void add(struct node **s,int c);
/*main program*/
int main()
{
struct node *p;
p = NULL;
add(&p,21);
return 0;
}

/* function */
void add(struct node **s,int c)
{
	struct node *r,*q=*s;

if(*s==NULL)
{
	*s = (struct node *)malloc(sizeof(struct node));
	(*s)->previous = NULL; 		/* (*s) ??? whats that ? */
	(*s)->next = NULL;
	(*s)->content = c
}
else
{
/*bla bla*/
}
}
----------------CODE END-------------------------------------
In the above code we can see the statement called "(*s)->previous = NULL;". I didnt get what exactly it means to be and how different is *s different from (*s) in this context. can it be written in any other form alternatively ? 
	thanks for the feedback,
regards,
KM


-----------------------------------------------------------------
On Tue, Oct 28, 2003 at 10:00:01AM -0200, Luciano Moreira - igLnx wrote:
> Try to think that p is a MACRO, like as (arbitrary macro):
> "#define p  pBaseList+5*(x->element)+1"
> 
> When you do:
> "p->next"
> it ll be:
> "pBaseList+5*(x->element)+1->next"
> 
> the code above seems to be unsafe, so, if you do:
> "(p)->next"
> or:
> "#define p  (pBaseList+5*(x->element)+1)"
> it ll free or code of  "precedence bugs".
> 
> Luciano
> 
> km wrote, On 28/10/2003 07:42:
> 
> >Hi all,
> >how different is the notation 
> >(p)->next (what do the parenthesis around the pointer signify ? )
> >different from  
> >p ( while p is a pointer)
> >
> >regards,
> >KM
> >
> >-
> >To unsubscribe from this list: send the line "unsubscribe 
> >linux-c-programming" in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >
> >
> > 
> >
> 
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html





  reply	other threads:[~2003-10-28 17:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-28  9:42 pointer notation km
2003-10-28 10:17 ` Thomas Steudten
2003-10-28 12:00 ` Luciano Moreira - igLnx
2003-10-28 17:46   ` km [this message]
2003-10-28 18:40     ` Mike Pastore
2003-10-28 18:46     ` Jeff Woods

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031028174605.GA5517@mrna.tn.nic.in \
    --to=km@mrna.tn.nic.in \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=lucianolnx@ig.com.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).