Expected unqualified-id before 'char'

Jacob Still

I am relatively new to the whole programming neighborhood and was playing around with the Arduino Duemilanove and the LOL shield. I had this great idea to turn it into a visual equalizer and lo and behold there were people already doing it here.

The Arduino works fine and I am able to get code running on it. Simple code, but still code.

I followed all the instructions on how to get it working and am pretty close. However, whenever I try to compile the .ino file for uploading to the board, it gives me 2 errors:

error #1:

C:\Users\Jacob\Documents\Arduino\libraries\FFT\fix_fft.cpp:130:13: error:
expected unqualified-id before 'char'
 int fix_fft(char fr[], char fi[], int m, int inverse)
             ^

error #2:

C:\Users\Jacob\Documents\Arduino\libraries\FFT\fix_fft.cpp:130:13: error:
expected ')' before 'char'
Error compiling.

Here is the source code (with large quantities of immaterial code removed):

#define fix_fft
#define __PROG_TYPES_COMPAT__
#include <avr/pgmspace.h>
#include "fix_fft.h"

/* fix_fft.c - Fixed-point in-place Fast Fourier Transform  */

#define N_WAVE      256    /* full length of Sinewave[] */
#define LOG2_N_WAVE 8      /* log2(N_WAVE) */

const prog_int8_t Sinewave[N_WAVE-N_WAVE/4] PROGMEM = {
0, 3, 6, 9, 12, 15, 18, 21, 
    …
};

inline char FIX_MPY(char a, char b)
{
    …
}

/*
 fix_fft() - perform forward/inverse fast Fourier transform.
 fr[n],fi[n] are real and imaginary arrays, both INPUT AND
 RESULT (in-place FFT), with 0 <= n < 2**m; set inverse to
 0 for forward transform (FFT), or 1 for iFFT.
*/

int fix_fft(char fr[], char fi[], int m, int inverse)
{
   int mr, nn, i, j, l, k, istep, n, scale, shift;
   char qr, qi, tr, ti, wr, wi;

   n = 1 << m;

   /* max FFT size = N_WAVE */
   if (n > N_WAVE)
       return -1;

   mr = 0;
   nn = n - 1;
   scale = 0;

   /* decimation in time - re-order data */
   for (m=1; m<=nn; ++m) {
       l = n;
       do {
           l >>= 1;
       } while (mr+l > nn);
       mr = (mr & (l-1)) + l;

       if (mr <= m)
           continue;
       tr = fr[m];
       fr[m] = fr[mr];
       fr[mr] = tr;
       ti = fi[m];
       fi[m] = fi[mr];
       fi[mr] = ti;
   }

   l = 1;
   k = LOG2_N_WAVE-1;
   while (l < n) {
      if (inverse) {
           /* variable scaling, depending upon data */
           shift = 0;
           for (i=0; i<n; ++i) {
               j = fr[i];
               if (j < 0)
                   j = -j;
               m = fi[i];
               if (m < 0)
               m = -m;
               if (j > 16383 || m > 16383) {
                   shift = 1;
                   break;
               }
           }
           if (shift)
               ++scale;
       } else {
           /*
             fixed scaling, for proper normalization --
             there will be log2(n) passes, so this results
             in an overall factor of 1/n, distributed to
             maximize arithmetic accuracy.
           */
           shift = 1;
       }
       /*
         it may not be obvious, but the shift will be
         performed on each data point exactly once,
         during this pass.
       */
       istep = l << 1;
       for (m=0; m<l; ++m) {
           j = m << k;
           /* 0 <= j < N_WAVE/2 */
           wr =  pgm_read_word_near(Sinewave + j+N_WAVE/4);

/*Serial.println("asdfasdf");
Serial.println(wr);
Serial.println(j+N_WAVE/4);
Serial.println(Sinewave[256]);

Serial.println("");*/


           wi = -pgm_read_word_near(Sinewave + j);
           if (inverse)
               wi = -wi;
           if (shift) {
               wr >>= 1;
               wi >>= 1;
           }
           for (i=m; i<n; i+=istep) {
               j = i + l;
               tr = FIX_MPY(wr,fr[j]) - FIX_MPY(wi,fi[j]);
               ti = FIX_MPY(wr,fi[j]) + FIX_MPY(wi,fr[j]);
               qr = fr[i];
               qi = fi[i];
               if (shift) {
                   qr >>= 1;
                   qi >>= 1;
               }
               fr[j] = qr - tr;
               fi[j] = qi - ti;
               fr[i] = qr + tr;
               fi[i] = qi + ti;
           }
       }
       --k;
       l = istep;
   }
   return scale;
}

…

There are other files in the audio conversion too.

Jonathan Leffler

What do you think this line does? Why do you think it is needed in your code at all?

#define fix_fft

When the preprocessor sees the line:

int fix_fft(char fr[], char fi[], int m, int inverse)

it is forced to translate that to:

int (char fr[], char fi[], int m, int inverse)

and now you can see why the compiler complains.

My preferred fix would be to remove the #define fix_fft line altogether. If you need it for some reason, you could either rename the macro that's defined (#define fix_fft_c to indicate that it's the fix_fft.c file) or rename the function that's defined (don't forget to edit the header that declares the function too — you do have a header to declare the function, don't you?), or (to be truly perverse), use #define fix_fft fix_fft. See the C standard, ISO/IEC 9899:2011 — §6.10.3.4 Rescanning and further replacement:

If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file’s preprocessing tokens), it is not replaced. Furthermore, if any nested replacements encounter the name of the macro being replaced, it is not replaced. These nonreplaced macro name preprocessing tokens are no longer available for further replacement even if they are later (re)examined in contexts in which that macro name preprocessing token would otherwise have been replaced.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

expected unqualified id before "." token

From Dev

Expected unqualified-id before 'xor' token

From Dev

Expected unqualified-id before '[' token

From Dev

expected unqualified-id before QDir directory

From Dev

Expected Unqualified-Id before 'delete' function

From Dev

Expected unqualified-id before ‘nullptr’

From Dev

error: expected unqualified-id before ‘const’

From Dev

Expected unqualified-id before '.' token

From Dev

expected unqualified-id before ')' token

From Dev

expected unqualified-id before ‘.’ token in vector

From Dev

expected unqualified-id before ‘->’ token

From Dev

Expected unqualified-id before 'xor' token

From Dev

error: expected unqualified-id before ‘const’

From Dev

error:expected unqualified-id before '=' token

From Dev

expected unqualified id before while c++

From Dev

error: expected unqualified-id before 'while'|

From Dev

error: expected unqualified-id before ‘)’ token

From Dev

Expected unqualified-id before numeric constant for defining a number

From Dev

C++ NetBeans error: expected unqualified-id before 'int'

From Dev

error: expected unqualified-id before ‘const’ on line 8

From Dev

Compile error for QT 5.2.1; expected unqualified-id before 'delete'

From Dev

Getting error: expected unqualified-id before 'default'

From Dev

C++ NetBeans error: expected unqualified-id before 'int'

From Dev

error: expected unqualified-id before ‘const’ on line 8

From Dev

Compile error for QT 5.2.1; expected unqualified-id before 'delete'

From Dev

C++ Error "expected unqualified-id '(' token" before debugging

From Dev

Unusual error: expected unqualified-id before ‘delete’/expected initializer before ‘delete’

From Dev

Parse Issue - expected unqualified id

From Dev

"error: expected unqualified-id before '.'" Compiling C++ App with OpenSSL Libraries

Related Related

  1. 1

    expected unqualified id before "." token

  2. 2

    Expected unqualified-id before 'xor' token

  3. 3

    Expected unqualified-id before '[' token

  4. 4

    expected unqualified-id before QDir directory

  5. 5

    Expected Unqualified-Id before 'delete' function

  6. 6

    Expected unqualified-id before ‘nullptr’

  7. 7

    error: expected unqualified-id before ‘const’

  8. 8

    Expected unqualified-id before '.' token

  9. 9

    expected unqualified-id before ')' token

  10. 10

    expected unqualified-id before ‘.’ token in vector

  11. 11

    expected unqualified-id before ‘->’ token

  12. 12

    Expected unqualified-id before 'xor' token

  13. 13

    error: expected unqualified-id before ‘const’

  14. 14

    error:expected unqualified-id before '=' token

  15. 15

    expected unqualified id before while c++

  16. 16

    error: expected unqualified-id before 'while'|

  17. 17

    error: expected unqualified-id before ‘)’ token

  18. 18

    Expected unqualified-id before numeric constant for defining a number

  19. 19

    C++ NetBeans error: expected unqualified-id before 'int'

  20. 20

    error: expected unqualified-id before ‘const’ on line 8

  21. 21

    Compile error for QT 5.2.1; expected unqualified-id before 'delete'

  22. 22

    Getting error: expected unqualified-id before 'default'

  23. 23

    C++ NetBeans error: expected unqualified-id before 'int'

  24. 24

    error: expected unqualified-id before ‘const’ on line 8

  25. 25

    Compile error for QT 5.2.1; expected unqualified-id before 'delete'

  26. 26

    C++ Error "expected unqualified-id '(' token" before debugging

  27. 27

    Unusual error: expected unqualified-id before ‘delete’/expected initializer before ‘delete’

  28. 28

    Parse Issue - expected unqualified id

  29. 29

    "error: expected unqualified-id before '.'" Compiling C++ App with OpenSSL Libraries

HotTag

Archive