www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/02/08/10:32:27

From: <ams AT ludd DOT luth DOT se>
Message-Id: <200302081532.h18FW3u24717@speedy.ludd.luth.se>
Subject: GCC warning - incompatible pointer type
To: djgpp AT delorie DOT com
Date: Sat, 8 Feb 2003 16:32:03 +0100 (CET)
X-Mailer: ELM [version 2.4ME+ PL78 (25)]
MIME-Version: 1.0
X-MailScanner: Found to be clean
X-MailScanner-Information: Please contact the ISP for more information
X-MailScanner-SpamScore: ss
Reply-To: djgpp AT delorie DOT com

In article <1391a.6717$kz5 DOT 662443 AT news1 DOT east DOT cox DOT net> Jason Kircher <cdrradar AT hold DOT odiferous DOT titilating DOT mail DOT com> wrote:
: Given buf is an array of 20 3-character strings that needs to be sorted, 
: I used the following:

: char buf[20][4];

To me it looks like buf is an array of 4 19-character strings.

: ...
: qsort (buf, 20, 4, strcmp);
          1   2   3     4

: gcc -Wall -o foo foo.c
: gcc gives me the warning:
: warning: passing arg 4 of `qsort' from incompatible pointer type

qsort expects a function taking two "const void *" arguments (and
returning an "int"). strcmp is a function taking two "const char *"
arguments.

Evidently the C idea of every pointer is compatible to "void *"
doesn't extend to "void *"s in functions.

: The program works fine, however, it's just that the warning spooks me. 
: Other than not saying -Wall, any idea how to get rid of this warning?

Why don't you "info libc a qsort" and see how the example solves this?

Alternatively is should be a safe to use strcmp directly (but don't
hold me to this in court), so a functioncast (if possible) would make
the compiler quiet.


Right,

						MartinS

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019