Thread: Help with assignment error

  1. #1
    Registered User
    Join Date
    Dec 2009
    Location
    Colorado
    Posts
    41

    Help with assignment error

    I am modifying some code (which I did not originally code) and have come in to this error upon compiling:

    Code:
    Lvalue required as left operand of assignment
    The problem occurs here:

    Code:
    temp + mat_col = (1.0 +  10.0 * rand() / ( RAND_MAX + 1.0 ) );
    where

    Code:
    float*     temp;
    temp = (float*) malloc(Order(local_A)*sizeof(float));
    and

    mat_col is the index of the for loop where the aforementioned error occurs

    Code:
    for(mat_col = 0; mat_col < Order(local_A); mat_col++)
    		temp + mat_col = (1.0 +  10.0 * rand() / ( RAND_MAX + 1.0));
    I am very confident that I am missing some subtlety with a pointer. I looked up this error it it seemed like it was a typecasting error but I don't see how that is the issue. Maybe 1.0 and 10.0 are treated as doubles by the computer and not floats - I feel like I might have read that before. Any suggestions? Thanks!

  2. #2
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    temp + mat_col is not a variable that something can be assigned to (an Lvalue).
    did you mean *(temp + mat_col) ?
    If you have any questions please ask.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  3. #3
    Registered User
    Join Date
    Dec 2009
    Location
    Colorado
    Posts
    41
    That did the trick. I guess I was changing the value of the pointer in the original code and what I should have been doing is changing to value at the address the pointer points to (by using the *(...) ) right? Thanks!

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, obviously.
    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.

  5. #5
    Registered User
    Join Date
    Dec 2009
    Location
    Colorado
    Posts
    41
    Quote Originally Posted by Elysia View Post
    Yes, obviously.
    I suppose if it were so obvious I wouldn't have asked the question in the first place. Either way, I appreciate the condescension.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't misunderstand me. It was meant to confirm your question.
    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. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM