Page 1 of 1

Need help

PostPosted: Fri Jun 26, 2009 12:23 pm
by jacobfernandas
• Hi all.

Code says more than thousand words
• PHP Code:
• int
main(int argc, char **argv)
{
char s[64]; /* s is of type (char *) here, right? */
char **p;

/*
* This assignment warns me about "assignment from incompatible
* pointer type"
*/
p = &s;

/*
* This works without warning. But as I'm not sure why I have to cast
* here I would like to avoid it... Or to make sure this is legal and
* not too bad style. So, what do you think about it?
*/
p = (char **)&s;

return (0);
}

• This gives me:
• Code:
• gcc -Wall --ansi test.c
• test.c: In function `main':
• test.c:11: warning: assignment from incompatible pointer type
• I would like to know why I get this warning and how I can avoid it "the right way".

Any help will be appreciated.




reputation management

Re: Need help

PostPosted: Sun Jun 28, 2009 4:29 pm
by forumgeek
For more information on this issue see:

http://www.lysator.liu.se/c/c-faq/c-2.html

2.4 answers your question, Business_Woman.

http://c-faq.com/aryptr/aryptr2.html

Code: Select all
   char            s[64]; 
        char          **p;
        p = &s;         
        return (0);
}


Please read "& operator applied to arrays does nothing." section of the below link:

http://www.fredosaurus.com/notes-cpp...pointers2.html

And one more:
http://publications.gbdirect.co.uk/c...ddress_of.html

I think this links will help...