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 8637203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:25:10+00:00 2026-06-12T10:25:10+00:00

The macro is like this: #define MAX 10000000 #define CNT 1000000 #define TIMER_INIT \

  • 0

The macro is like this:

#define MAX 10000000
#define CNT 1000000
#define TIMER_INIT             \
    clock_t starttime, endtime;    \
#define TIMER(txt, process)                     \
    starttime = clock();                        \
    process;                            \
    endtime = clock();                      \
    printf("%-20s %20ld\n",                     \
           txt, (endtime - starttime))

The main codes is like this:

char vector2[CNT/8 + 1];

TIMER(  "bitsort",
        for(i = 0; i < CNT; ++i)
            set1(rand() % MAX, vector2));

And the set1 function is like this:

void set1(int pos, char* vector)        /* set the position to 1 */
{
    vector[pos/8] |= (0x1 << pos%8);
}

When I execute the program, the output looks like this..

bitsort                -36035411302143896

Even if I cast the difference to unsigned int like this, it still doesn’t work:

#define TIMER(txt, process)                     \
    starttime = clock();                        \
    process;                            \
    endtime = clock();                      \
    printf("%-20s %20d\n",                      \
           txt, (unsigned int)(endtime - starttime))

Output is bitsort -16766097

I tried to modify %ld to %d, but it doesn’t work.

But if I don’t use for in the parameter, like this:

TIMER("bitsort", set1(rand() % MAX,vector2));

The TIMER works perfectly and gives me a reasonable result..

Does anyone have idea about what’s wrong with my code? Is it caused by macro or by clock() function? Thanks!

  • 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-12T10:25:12+00:00Added an answer on June 12, 2026 at 10:25 am

    I have found your issue:

    Look at this documentation http://www.cplusplus.com/reference/clibrary/cstdio/printf/

    Notice something about %d and %i? Signed decimal integer

    You must use %u or %lu because clock_t is unsigned, and an unsigned int is also obviously unsigned.

    Edit: This was only half of the problem, the other half was that he was destroying his stack(MAX is larger than CNT) in the bitsort function, thanks to @nneonneo in the chat for finding that.

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

Sidebar

Related Questions

If you have a macro like this in C: #define SLICE_VERSION 20110614 How to
i'm having trouble trying to define this function-like macro, which takes 4 vector magnitudes
Can you do something like this with a macro in C ? #define SUPERMACRO(X,Y)
Say I have a macro like this: #define SET_TYPE_NAME(TYPE, NAME) \ template<typename T> \
I have macro like this: #define error_exit(format, ...) \ error_at_line(EXIT_FAILURE, 0, __FILE__, __LINE__, format,
I have a macro defined in C something like this: #define SOME_FIELD(_A_,_B_,_C_) \ MyObj[
We have a macro for error-checking that goes like this: #define CheckCondition( x )
I want to use a macro like this #define Return(x) {call_my_function(); return (x);} is
When using C preprocessor one can stringify macro argument like this: #define TO_STRING(x) a
In python's source code, there are some macro definitions like this: #define PyObject_HEAD \

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.