473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

GMP: Cannot operate on vector<mpz_t>

#include <gmp.h>

vector<mpz_t> v_bigints; v_bigints.resize(20);

This fails.

error: ISO C++ forbids casting to an array type '__mpz_struct[1]' (GCC
on a G4)

What's wrong with this? (GMP mailing lists were closed today, sorry).
Jul 23 '05 #1
3 5131
Richard Cavell wrote:

#include <gmp.h>

vector<mpz_t> v_bigints; v_bigints.resize(20);

This fails.

error: ISO C++ forbids casting to an array type '__mpz_struct[1]' (GCC
on a G4)

What's wrong with this? (GMP mailing lists were closed today, sorry).


As has been told otherthread, the type mpz_t is defined in a way which
makes this impossible. It is a 'clever hack' to avoid a few keystrokes.
(So much for clever hacks :-)

You could try using __mpz_struct directly.

vector < __mpz_struct > v_bigints;
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #2
On Fri, 18 Feb 2005 22:28:52 +1100, Richard Cavell
<ri***********@mail.com> wrote:
#include <gmp.h>

vector<mpz_t> v_bigints; v_bigints.resize(20);

This fails.

error: ISO C++ forbids casting to an array type '__mpz_struct[1]' (GCC
on a G4)

What's wrong with this? (GMP mailing lists were closed today, sorry).


See my reply in thread "Cannot 'new' a GMP object", Message-ID

<sl******************@ccserver.keris.net>

mpz_t is defined as a 1-element array, to make using the C GMP functions
easier, which blows the C syntax for containers and new. Plus it is
risky, since you will have to ensure that each of the elements is
correctly initialised and cleared whenever you resize the vector
otherwise you will get momory leaks. The C++ class versions are much
easier to us.

Chris C
Jul 23 '05 #3
On 19/2/05 12:18 AM, Karl Heinz Buchegger wrote:
vector < __mpz_struct > v_bigints;


That doesn't work either.

Thanks to everyone for their help.

For the record, my solution is like this:

mpz_t myMPZArray[3000]; // This works

for (int i=0; i<NumberOfMPZNeeded; i++)
{
// Initialize and operate on myMPZArray[i];
}

Which wastes up to 3000 * sizeof (mpz_t) bytes of RAM and means I have
to change a constant in my program to get more than 3000, but it does
work...
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alexander Skwar | last post by:
Hello! I'm having problems getting PHP 4.3.3RC4 successfully to install on my HP-UX 11.00 server. After a (successfull?) compile, "make install" errors out with this error message: ...
0
by: Jasper | last post by:
Hello Perlers, I followed the directions on how to install GNU GMP for windows (below and on the URL) http://www.cs.nyu.edu/exact/core/gmp/ and I don't notice any performance gain..in Perl one is...
0
by: Jasper | last post by:
Hello, I am truly stuck after several failed attempts on Win XP ..can anyone please assist here. I was told "activestate perl is compiled by MS visual c++, it cannot use library files...
0
by: anonymous | last post by:
I cannot compile LiDIA mathematical library version 2.1pre5 with the gmp 4.1.2 multiprecision library because the gcc compiler ver 3.2.2 20030222 Red Hat Linux 9 complains about some structures in...
1
by: Jasper | last post by:
Hello c++'ers, I followed the directions on how to install GNU GMP for windows (below and on the URL) http://www.cs.nyu.edu/exact/core/gmp/ and I don't notice any performance gain..in Perl one is...
4
by: neehakale | last post by:
I m trying to write an event for the CheckedListBox...here m using foreach loop syntsx: (type identifier in expression) but it is giving error :foreach statment cannot operate on variables of...
0
by: dot | last post by:
I spent a few headache filled days trying to use GMP on windows (XP pro) I finally got it to work and since I found little help on the Web I thought someone might find what i did useful. ...
2
boss32178
by: boss32178 | last post by:
Ok I get this error when i try to run the web app. foreach statement cannot operte on variables of type 'object' does not contain a public definition for 'GetEnumerator' here is the code #region...
0
by: ikilobo | last post by:
i want to representation the large random bit to operate the arithmetic, like this example input n=10, then 10 random bit has create A= B= i want to divide the array to any part like A=,]
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.