Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:00:33+00:00 2026-06-09T18:00:33+00:00

We have some code in spatialite that looks like: static int cmp_pt_coords (const void

  • 0

We have some code in spatialite that looks like:

static int cmp_pt_coords (const void *p1, const void *p2)
{
    ....
}

static gaiaGeomCollPtr auxPolygNodes (gaiaGeomCollPtr geom)
{
    ....
/* sorting points by coords */
    qsort (sorted, count, sizeof (gaiaPointPtr), cmp_pt_coords);
    ....
}

This is obviously simplified – the real code can be seen at
https://www.gaia-gis.it/fossil/libspatialite/artifact/fe1d6e12c2f98dff23f9df9372afc23f745b50df

The error that I’m getting from gcc (gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)) is

/bin/bash ../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../.. -g  -Wall -Werror -fprofile-arcs -ftest-coverage -g -I../../src/headers   -fvisibility=hidden -g -Wall -Werror -fprofile-arcs -ftest-coverage -g -MT libsplite_la-spatialite.lo -MD -MP -MF .deps/libsplite_la-spatialite.Tpo -c -o libsplite_la-spatialite.lo `test -f 'spatialite.c' || echo './'`spatialite.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../.. -g -Wall -Werror -fprofile-arcs -ftest-coverage -g -I../../src/headers -fvisibility=hidden -g -Wall -Werror -fprofile-arcs -ftest-coverage -g -MT libsplite_la-spatialite.lo -MD -MP -MF .deps/libsplite_la-spatialite.Tpo -c spatialite.c  -fPIC -DPIC -o .libs/libsplite_la-spatialite.o
spatialite.c: In function 'auxPolygNodes':
spatialite.c:17843:5: error: passing argument 4 of 'qsort' from incompatible pointer type [-Werror]
/usr/include/stdlib.h:761:13: note: expected '__compar_fn_t' but argument is of type 'int (*)(void *, void *)'
cc1: all warnings being treated as errors

I’ve looked at some previous postings:

  • What are the parameters in this C qsort function call?
  • Warning when using qsort in C

However they don’t really seem the same (or at least, the way I read the suggestions in those postings is what I think we’re already doing here).

I can cast around this, using:

    qsort (sorted, count, sizeof (gaiaPointPtr), (__compar_fn_t)cmp_pt_coords);

However I don’t see why that should be necessary, and I’m worried about portability to other systems. It seems like the compiler is omitting the const-s from the arguments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:00:35+00:00Added an answer on June 9, 2026 at 6:00 pm

    That cast is perfectly fine. GCC isn’t smart enough to know that __compar_fn_t is

    int (*)(const void *, const void *)
    

    so it issues a warning.

    However, __compar_fn_t is not portable — so if you don’t want to use it for casting, you should probably make GCC not warn about this using an appropriate compiler flag.

    Or you can see whether __compar_fn_t is defined, and if not, define it yourself:

    #ifndef __GNUC__
    typedef int (*__compar_fn_t)(const void *, const void *);
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that looks something like this: d = {'foo': True, 'bar':
I have some code like that: class MainApplication { protected static string _since; protected
We have some code that looks like this: class Serializer { public: template<class Type>
I have some code that looks like this: NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions
I have some code like that: class MyApp(Ui_MainWindow): def __init__(self): pass def setupUi(self, *args):
I have some code that will change the background color of a specific label
I have some code here that uses bitsets to store many 1 bit values
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.