This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
coding question
- From: "Moreno, Cesar A" <cesar dot a dot moreno at lmco dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Cc: "Moreno, Cesar A" <cesar dot a dot moreno at lmco dot com>
- Date: Tue, 11 Dec 2018 21:31:11 +0000
- Subject: coding question
HOW do I malloc or new an array of complex numbers in GNU C++ code ?
MALLOC does not work, how do I use MALLOC correctly or NEW ?
I made a struct called complex (for a complex number with realp and imagp)
And I want to make an array of 128 locations (where each location includes a realp and imagp)
Struct complex
{
Float realp;
Float imagp;
}
// tdin is a pointer to an array of complex numbers
complex* tdin;
// form the array with MALLOC or whatever works in GNU C++
tdin = (complex*) malloc ( 128 * sizeof (complex) );
then I can print the contents of the array with
for (int k; k<128; k++)
{ cout << tdin[k].realp << " and " << tdin[k].imagp << "endl";