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

  • Home
  • SEARCH
  • 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 8081981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:55:33+00:00 2026-06-05T16:55:33+00:00

I found Swenson’s C implementation of Timsort: https://github.com/swenson/sort mentioned in one of the older

  • 0

I found Swenson’s C implementation of Timsort:
https://github.com/swenson/sort mentioned in one of the older SO questions.

I encountered two problems:

1)To use it I need to define SORT_CMP macro suitable for the type I want to sort.
My type is defined as (a bit simplified here):

typedef struct{
    int a;
    int b;
} MyType

I try to define:

#define SORT_TYPE MyType
#define SORT_CMP(x,y) (x.a - y.a)

but I keep getting an error: “request for member ‘a’ in something not a structure or union”
I thought that maybe x and y will be pointers but:

#define SORT_CMP(x,y) (x->a - y->a)

doesn’t work either.
Could you please help me with that? I am C newbie and probably missing something basic.

2)Is there any way to compile that code in Visual Studio ? It uses stuff from newer C standard (like declarations in the middle of the block) and cl.exe doesn’t accept it. I compiled it using GCC (mingw) but mingw is 20% slower for the rest of my code than VC (with O2 or O3 flag vs lc.exe with /Ox) so any gains which I could have from using Timsort instead of stdlib qsort won’t make up for that. The same goes for Pelles compiler.
Most of my data has a lot of partially sorted sequences and sorting takes about 50% of the execution time so I feel there is gain to make here assuming I make it work in VC.

  • 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-05T16:55:34+00:00Added an answer on June 5, 2026 at 4:55 pm

    You might try adding parentheses around the macros parameters like so:

    #define SORT_CMP(x,y) ((x).a - (y).a)
    

    Most probably the macro is used with a dereferenced pointer to a SORT_TYPE variable:

    SORT_TYPE * pMyTypeVar1, pMyTypeVar2;
    ...
    SORT_CMP(*pMyTypeVar, *pMyTypeVar2);
    

    If then those parentheses around the macro’s parameters are missing the preprocessor produces something like this:

    (*pMyTypeVar1.a - *pMyTypeVar2.a)
    

    And as the dot-operator binds tighter than the star-operator the compiler tries to find the member a for the pointers pMyTypeVar1 and pMyTypeVar2 which won’t work.

    Using parentheses as proposed would lead to:

    ((*pMyTypeVar1).a - (*pMyTypeVar2).a)
    

    This way the compiler first dereferences pMyTypeVar1 and pMyTypeVar2 and finally is able to find member a.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Found two libraries Rebex ( www.rebex.net ) and QuikSoft ( www.quiksoft.com ) any comments
Found this one http://www.kite9.com/content/adl-new-visual-language-part-2 (presentation here http://www.kite9.com/content/muddle-uml ) not cheap :( Any others that
found this runtime INotifyPropertyChanged generator http://www.codeproject.com/Articles/141732/Automatic-Implementation-of-INotifyPropertyChanged wondering if there is a static generator to
Found on JavaScript SDK http://developers.facebook.com/docs/reference/javascript/ ... Asynchronous Loading -------------------------------- This code loads the SDK
Found this official ACS demo http://www.fabrikamshipping.com/ while researching on ACS. In the app itself,
Found the answer here (last post): http://social.msdn.microsoft.com/Forums/eu/wcf/thread/f5c0ea22-1d45-484e-b2c0-e3bc9de20915 I'm having one last issue with the
Found similar questions but nothing that covers exactly what I need. I kept it
Found a couple of similar questions here on this, but couldn't figure out how
Found a couple of similar questions here on this, but couldn't figure out how
I found a tutorial to create android custom button : http://developer.android.com/resources/tutorials/views/hello-formstuff.html#CustomButton What is the

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.