Thread: confused abut pointers

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    77

    confused abut pointers

    hi all,
    I've a truble with slimilar of this code..
    Code:
    struct first *st;
    struct second *q;
    func(struct f *s, struct s *ku){
    ......
    return func(s,ku);
    }
    errno=func(q,st); //warning: passing argument 2 of 'func' from incompatible pointer type
    I wrote two equal methog structs usage, but second take it's warning. Why it's happened?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    because types of parameters are different in 2 calls
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    77
    Quote Originally Posted by vart View Post
    because types of parameters are different in 2 calls
    where? I'm not posted any syscalls, or what's calls?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    s and q are of types struct f * and struct s * (parameters passed in the line return func(s,ku); )

    q and st are of types struct second * and struct first * (passed in the line errno=func(q,st); ) which is different from struct f * and struct s *
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    77
    possible I take a mistake in that sapmle. please, can you tell me it more clearly?
    there..

    Code:
    struct first *fir;
    struct second *sec;
    func(struct firs *fi, struct s *se){
    ......
    return func(fi,se); // return value from func which take pointer on struct firs  and s
    }
    errno=func(fir,sec); // take pointer on struct first  and second
    //warning: passing argument 2 of 'func' from incompatible pointer type

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    struct s != struct sec

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    77
    Quote Originally Posted by matsp View Post
    struct s != struct sec
    ok, what I should do so as to improve this?
    I want to input two structs into func.

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by quantt View Post
    ok, what I should do so as to improve this?
    I want to input two structs into func.
    there is nothing to improve. You should decide what type parameters of the function are and provide exactly that type of variables
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Hey guys..need help on pointers
    By Darkozuma in forum C++ Programming
    Replies: 5
    Last Post: 07-25-2008, 02:57 PM
  3. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  4. confused with pointers
    By Mahdi123 in forum C Programming
    Replies: 2
    Last Post: 04-25-2007, 01:08 PM
  5. Replies: 4
    Last Post: 12-10-2006, 07:08 PM