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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:03:38+00:00 2026-06-18T00:03:38+00:00

Compiler threw a SIGSEGV at tmp = pow(p[i],j); while p[i] and j are two

  • 0

Compiler threw a SIGSEGV at tmp = pow(p[i],j); while p[i] and j are two integers, and p[i] is a valid element of array p, I really don’t know why…

Original code is here:http://pastebin.com/DYhGeHxm

  • 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-18T00:03:39+00:00Added an answer on June 18, 2026 at 12:03 am

    Has it occurred to you that this:

    int i,j,p[2000], a[5000000],num,count,tmp;
    

    may be pushing you either very near, or outright over the brink of your stack space? That is

    4 + 4 + 8000 + 20000000 + 4 + 4 + 4
    

    bytes

    I.e. you have a 19.08 megabyte stack space declaration. Consider dynamically allocating a at least. When i changed it to be:

    int *a = malloc(5000000 * sizeof(*a));
    

    and reran the code, it made it well past the seg-fault you have. unfortunately, it died at this location:

    count = 0;
    for(i = 0; i < num; i++) {
        for(j = 2; ;j++) {
            tmp = pow(p[i],j);
            if(tmp > 5000000) break;
            a[count++] = tmp; // <=== faulted here, count was 5000193
        }
    }
    

    Both loops should break when you reach the allocated max size of a[]. I did the following. At the top of main():

    static const int a_max = 5000000;
    int *a = malloc(a_max*sizeof(*a));
    

    Down in the loop:

    count = 0;
    for(i = 0; i < num && count < a_max; i++)
    {
        for(j = 2; count < a_max; j++)
        {
            tmp = pow(p[i],j);
            if(tmp > 5000000)
                break;
            a[count++] = tmp;
        }
    }
    

    This gets you past all the setup. The last thing is the quicksort algorithm itself, which appears broken as well. I highly advise starting with smaller data sizes to debug that.

    Best of luck.


    EDIT In case you needed a reference quicksort algorithm, i had one sitting in a source file in one of my junk folders. No guarantees its even right (pretty sure it is, and skips length-1 sorts too), but I know it doesn’t hang, so it has that going for it =P

    // quicksort for ints
    static void quicksort_ints(int *arr, int left, int right)
    {
        int p = (left+right)/2;    // as good as any
        int l = left, r = right;   // movable indicies
    
        while (l <= r)
        {
            while (arr[l] < arr[p])
                ++l;
            while (arr[r] > arr[p])
                --r;
            if (l <= r)
            {
                int tmp = arr[l];
                arr[l] = arr[r];
                arr[r] = tmp;
                ++l;
                --r;
            }
        }
    
        if (left < r)
            quicksort_ints(arr, left, r);
        if (l < right)
            quicksort_ints(arr, l, right);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The compiler doesn't know where stat.h is? Error: c:\Projects\ADC_HCI\mongoose.c(745) : error C2079: 'st' uses
EDIT: solved, I know how but I don't understand why. I changed variables declaration
I know following cyclic inheritance hierarchy is not allowed in Java. Compiler throws an
When calling functions that always throw from a function returning a value, the compiler
My compiler expands it to 199711L. What does that mean? I read that __cplusplus
My compiler errors are extremely long because g++ tells me the many 'candidates' for
In compiler design, why instead of having a caller or callee register saving arrangement,
While trying to load from the database, I am getting the following errors in
Is it possible to use the Bindable compiler setting when using mxml? I've got
I am trying to get to the bottom of an issue with our compiler

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.