Thread: help about error: lvalue required left operand assignment c

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    9

    help about error: lvalue required left operand assignment c

    Hi all,
    I am working with complex number and using fftw library ( FFTW Home Page ) to compute fft of some data. But when I am compiling my following simple piece of code , I am getting the above mentioned error.
    Code:
    #define re(c) ((c)[0])		///< real part of a complex number  as defined by fftw_complex in fftw 
    #define im(c) ((c)[1])
    #include <fftw3.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    unsigned int fs = 16367600;	
    double fif = 4.1304E6;
    double range = fif;		
    double span = 10E3;		
    double fd_step = 500;	
    double Tint = 1;
     unsigned int l,C1,D1;		
    int main()
    {
                C1 = ceil((double) fs * 1E-3);
        	    D1 = ceil(span / fd_step) + 1;
                
                SUM_SS = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * C1 * D1);
                if (SUM_SS == NULL) {
    		fprintf(stderr, "Error allocationg memory fftw operations \n");
    		
        	    }
        	    for (l = 0; l < C1 *D1; l++) {
    		re(SUM_SS[l]) = 0.0;
    		im(SUM_SS[l]) = 0.0;
       	    }
    }
    fftw_malloc behaves like malloc except that it properly aligns the array when SIMD instructions (such as SSE and Altivec) are available. The data is an array of type fftw_complex, which is by default a double[2] composed of the real (in[i][0]) and imaginary (in[i][1]) parts of a complex number.


    The error is reported on line re(SUM_SS[l]) = 0.0; and im(SUM_SS[l]) = 0.0; and reported error is
    error: lvalue required as left operand of assignment

    Please help me

    Thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    How is SUM_SS declared?????
    Code:
    #define re(c) ((c)[0])		///< real part of a complex number  as defined by fftw_complex in fftw 
    #define im(c) ((c)[1])
    Are you sure that it's the correct macro to access real,imag part??
    Last edited by Bayint Naung; 06-01-2010 at 04:28 AM.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    9
    Sorry.... for error in posting the code

    Code is :
    Code:
    #define re(c) ((c)[0])		///< real part of a complex number  as defined by fftw_complex in fftw 
    #define im(c) ((c)[1])
    #include <fftw3.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    unsigned int fs = 16367600;	
    double fif = 4.1304E6;
    double range = fif;		
    double span = 10E3;		
    double fd_step = 500;	
    double Tint = 1;
     unsigned int l,C1,D1;	
    fftw_complex *SUM_SS;
    	
    int main()
    {
                C1 = ceil((double) fs * 1E-3);
        	    D1 = ceil(span / fd_step) + 1;
                
                SUM_SS = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * C1 * D1);
                if (SUM_SS == NULL) {
    		fprintf(stderr, "Error allocationg memory fftw operations \n");
    		
        	    }
        	    for (l = 0; l < C1 *D1; l++) {
    		re(SUM_SS[l]) = 0.0;
    		im(SUM_SS[l]) = 0.0;
       	    }
    }

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What seems to be the error is that fftw_complex is a structure and you have a pointer to it. Hence, SUM_SS[l] is a fftw_complex, thus the macro expands to:
    SUM_SS[1][0] which won't work since fftw_complex is not an array. This is what I can guess from the code you have posted.
    Also, make sure to move all your global vars into main. And the variables you don't intend to change should be const.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lvalue required as left operand of assignment (??)
    By oospill in forum C Programming
    Replies: 3
    Last Post: 11-03-2009, 11:02 PM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM