#1
  1. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12

    why this pointer mismatch warning?


    some code from a book gives this warning when i compile it:

    warning: pointer type mismatch in conditional expression

    the line that's warned about is:
    Code:
    qsorty((void **) lineptr, 0, nlines-1, (int (*)(void *, void *))(numeric ? numcmp : strcmp));
    so it would indicate that there's something up with this bit maybe :

    numeric ? numcmp : strcmp

    the code does work, so maybe it doesn't matter? but i'm wondering why i get the warning. it's from the k&r book which seems to be generally pretty accurate and correct. i'm fairly sure i've typed it in correctly.

    2 decleration lines that appear before the above line, that might be usefull to see are :
    Code:
    void qsorty(void *lineptr[], int left, int right, int (*comp)(void *, void *));
    int numcmp(char *, char *);
    why does it give a warning?
  2. #2
  3. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    Well, on my Linux box, strcmp appears to have the following prototype:

    Code:
    int strcmp(const char *s1, const char *s2);
    So it's probably complaining about the type mismatch of the functions parameters. This makes sense, since (if your K&R is the first edition) strcmp used to be defined as having parameters of type *void.

    Anyway, I wouldn't worry about it too much.
    Last edited by Analyser; April 7th, 2003 at 12:58 PM.
    "A poor programmer is he who blames his tools."
    http://analyser.oli.tudelft.nl/
  4. #3
  5. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    where is the source code for the already-written-for-you functions? or how do you go about finding that out? - to find out stuff like:
    int strcmp(const char *s1, const char *s2);
    This makes sense, since (if your K&R is the first edition) strcmp used to be defined as having parameters of type *void.
    no, it's from the 2nd edition.
    Anyway, I wouldn't worry about it too much.
    sounds good to me. thanks.
  6. #4
  7. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    Originally posted by balance
    where is the source code for the already-written-for-you functions? or how do you go about finding that out? - to find out stuff like:
    check out the .h file. like for that strcomp i believe it is contained in string.h . another great source is msnd.com. all u do is type in the function name, strcmp() and it will return a whole bunch of useful stuff describing it.
    edit: here check out this link for strcmp() on MSDN.
    strcmp
    Last edited by infamous41md; April 7th, 2003 at 09:43 PM.
  8. #5
  9. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    check out the .h file. like for that strcomp i believe it is contained in string.h
    oh yeah, it says
    Code:
    int	 strcmp __P((const char *, const char *));
    for strcmp.

    what about if you want to look at the actual strcmp implementation? or is that secret?

    another great source is msnd.com. all u do is type in the function name, strcmp() and it will return a whole bunch of useful stuff describing it.
    that's pretty useful - thanks.
  10. #6
  11. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    what about if you want to look at the actual strcmp implementation? or is that secret?
    That's the difference between open source and proprietary software :) There's no way of finding out (other than becoming a programmer for Microsoft, obviously) to know how MS have implemented the strcmp() function in their C library.

    The source code for the GNU C library, though, is freely available, as is the code for most *BSD Unix C libraries. For example, here's the code for OpenBSD's implementation of strcmp().

    Oh, and the site that infamous41md recommended is actually msdn.com, MSDN being short for MicroSoft Developer Network.

    On most unix systems, you can type man <function_name> at the prompt to get a description for a function. YMMV.
    "A poor programmer is he who blames his tools."
    http://analyser.oli.tudelft.nl/
  12. #7
  13. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    For example, here's the code for OpenBSD's implementation of strcmp().
    oh yup, that's great. i'm using a bsd unix based system - so that's exactly what i was after. thanks.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    That's the difference between open source and proprietary software There's no way of finding out (other than becoming a programmer for Microsoft, obviously) to know how MS have implemented the strcmp() function in their C library.
    Actually, the source to the MS C runtime ships with the compiler/development environment and has for many years.
  16. #9
  17. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    Not having done any Windows programming myself, I feared I'd get corrected on this one :D
    "A poor programmer is he who blames his tools."
    http://analyser.oli.tudelft.nl/
  18. #10
  19. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    Originally posted by balance

    what about if you want to look at the actual strcmp implementation? or is that secret?
    = i was just thinkin.... im pretty sure if u look at the disassembled code u could get a pretty good idea of how strcmp() works? when i get to my other comp. i will try it out.

IMN logo majestic logo threadwatch logo seochat tools logo