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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:20:22+00:00 2026-06-19T00:20:22+00:00

I want to load 64 bit integers into gmp using the mpz_import method, I

  • 0

I want to load 64 bit integers into gmp using the mpz_import method, I am aware I could achieve this by streaming the number out to a string and then using the assign operator but this is surely slower and sub-optimal.

This code runs fine on my 64bit MacBook running OSX, however fails with segmentation fault on a raspberry pi running Raspbian, 32 bit Ubuntu Server and 64bit Linux Mint, all fail on the mpz_import line.

Here’s the code, compiled with gcc 4.7 g++ -std=c++11 -lgmp -lgmpxx main.cpp

#include <iostream>
#include <cstdint>
#include <gmp.h>
#include <gmpxx.h>

using namespace std;

int main()
{
    mpz_t a;
    int64_t b = 4;
    mpz_import(a, 1, 1, sizeof(b), 0, 0, &b); //segfault on this line
    mpz_class c(a);
    cout << c << endl;
}
  • 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-19T00:20:23+00:00Added an answer on June 19, 2026 at 12:20 am

    You need to mpz_init a before using it in mpz_import. From the documentation:

    unsigned long  a[20];
    /* Initialize z and a */
    mpz_import (z, 20, 1, sizeof(a[0]), 0, 0, a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to load external websites inside div and make it a bit smaller
I want to load the form fields using json data. I am using extjs
I want to load multiple variables into one .mat file at the end of
I want to load a data structure into a Ruby script which maps a
I want to take an external json file (locations.json) and load the contents into
Basically I want to load a HTML document and using controls such as multiple
i need some help i want to load an xml file into a table
I want to do 2 things: 1) Load 8 bit grayscale image as 8
I want to load an image into the background of my Flex app. However,
Could somebody get me started with the following idea: I want to load an

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.