void DBG () {
return;
}
/* */
/* Complex Numbers. */
/* ================ */
/* complex number */
struct C {
float re,
im;
} ;
/* multply real, complex */
#define C_MUL( f, z) \
do { \
z.re *= f; z.im *= f; \
} while (FALSE)
/* complex product constructor */
#define C_PRO( z1, z2) { \
re: z1.re * z2.re - z1.im * z2.im, \
im: z1.re * z2.im + z1.im * z2.re \
}
/* bit reverse permutation */
void BRP (unsigned char ldN,
struct C vec []) /* 2^ldN */ // <<========================== ERROR !
{
unsigned int N;
unsigned int l, n, r;
unsigned char b;
N = 1 << ldN;
for (l = 0; N > l; ++ l)
{
n = l;
r = 0;
for (b = 0; ldN > b; ++ b) {
r <<= 1;
if (0 != 1 & n ) { r |= 1; }
n >>= 1;
} // b
if (l < r) {
struct C const z = vec [l];
vec [l] = vec [r];
vec [r] = z;
} // right
} // k
return;
} // BRP
task main() {
}
# Error: Unexpected character encountered
File "c:\Temp\temp.nxc" ; line 30
# struct C v
#----------------------------------------------------------
# Error: Variable name expected
File "c:\Temp\temp.nxc" ; line 30
# struct C v
#----------------------------------------------------------
# Error: Unknown datatype
File "c:\Temp\temp.nxc" ; line 30
# struct C v
#----------------------------------------------------------
# Error: Variable name expected
File "c:\Temp\temp.nxc" ; line 32
# unsigned int const N
#----------------------------------------------------------
# Error: ';' expected
File "c:\Temp\temp.nxc" ; line 32
# unsigned int const N =
#----------------------------------------------------------
You should only use "struct" at the declaration, just use "C" at the other places. The syntax by using "struct" each time it is needed actually looks weird to me but looking it up it really is the way it is supposed to be done in C... Did they change it in C++, or have I just always used classes instead?
I'm actually not sure if it's C or C++ code -
I just picked up the code while searching for implementations of a DFT(FFT) and now I despair of the error messages trying to use that code for NXC... ;)
edit: got the complex calculations working now, thx! :)
spillerrec wrote:You should only use "struct" at the declaration, just use "C" at the other places. The syntax by using "struct" each time it is needed actually looks weird to me but looking it up it really is the way it is supposed to be done in C... Did they change it in C++, or have I just always used classes instead?
Yes, in Standard C a type defined with 'struct' must always be referred to as 'struct X'. This is why you often see code such as