• C

TypeDef Struct Variable to different #define statement during variable init.

the TI demo code provided the statement (without error). I need help to understand and fix this error.

RFFT32  fft=RFFT32_512P_DEFAULTS;  (There are 6 different default setting).

I wish to implement switch statement which setup the fft to different setting

RFFT32  fft;

case 0:
    fft = RFFT32_512P_DEFAULTS;
   break;
case 1:
    fft = RFFT32_256P_DEFAULTS;
   break;
case 2:
    fft = RFFT32_128P_DEFAULTS;
   break;

However the compiler report error "Error expected a expression".

I have tried fft = (RFFT32 ) RFFT32_128P_DEFAULTS; but no luck as it report error (RFFT32) is not allowed

The compiler is Code Composer V6 (from TI) which is based on Eclipse.

There are 6 different default based on RFFT32_512P_DEFAULTS
RFFT32_512P_DEFAULTS
RFFT32_256P_DEFAULTS
RFFT32_128P_DEFAULTS, etc

where RFFT32_512P_DEFAULTS has the following code provided by TI example code.
//------------------------------------------------------------------------------------
#define RFFT32_512P_DEFAULTS    { (long *)NULL,\
        (long *)NULL,\
        512,\
        9,\
        (long *)NULL,\
        (long *)NULL,\
        0,\
        0,\
        8,\
        (void (*)(void *))FFT32_init,\
        (void (*)(void *))FFT32_calc,\
        (void (*)(void *))FFT32_mag,\
        (void (*)(void *))FFT32_win
}
//-------------------------------------------------------------------------
The RFFT32  typedef struct has the following statement

typedef struct {  
        long *ipcbptr;
        long *tfptr;              
        int size;
        int nrstage;            
        long *magptr;
        long *winptr;
        long peakmag;
        int peakfrq;
            int ratio;
        void (*init)(void *);
        void (*calc)(void *);
        void (*mag)(void *);
        void (*win)(void *);
        }RFFT32;
typedef RFFT32 *RFFT32_handle;
Richard PayneChief Technology EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
There should be a \ at the end of
 (void (*)(void *))FFT32_win

#define RFFT32_512P_DEFAULTS    { (long *)NULL,\
        (long *)NULL,\
        512,\
        9,\
        (long *)NULL,\
        (long *)NULL,\
        0,\
        0,\
        8,\
        (void (*)(void *))FFT32_init,\
        (void (*)(void *))FFT32_calc,\
        (void (*)(void *))FFT32_mag,\
        (void (*)(void *))FFT32_win\
}
0
Richard PayneChief Technology EngineerAuthor Commented:
Thank, I actually put the '}' there to make it clearer where it suppose to be

(void (*)(void *))FFT32_win}

as original code.

This does not resolve problem.....Anyone?
0
ozoCommented:
switch(0){
 case 0:
   {RFFT32 f=RFFT32_512P_DEFAULTS;
   fft = f;
   break;}
}
0
sarabandeCommented:
to add to ozo's solution:

the point is that you only can initialize a struct with an initializer block {} but not assign a block to a variable.

so you could initialize helpers and assign the helper variables :

RFFT32  fft;
RFFT32  fft0 = RFFT32_512P_DEFAULTS;
RFFT32  fft1 = RFFT32_256P_DEFAULTS;
....

 case 0:
     fft = fft0;
    break;
 case 1:
     fft = fft1;
     ...

Open in new window


Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.