By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,069 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,069 IT Pros & Developers. It's quick & easy.

invalid lvalue in increment error

P: 1
Expand|Select|Wrap|Line Numbers
  1. /* after changing GCC version 3.0 to 4.1 i am getting invalid lvalue in increment error */
  2.  
  3. #include <vscreen.h>
  4. #include "vscreen_internal.h"
  5.  
  6. extern UDINT colPalette[256];
  7.  
  8.  
  9. void  memset_f(void *p,USINT value, UDINT len)
  10. {
  11.        register    UDINT longValue = colPalette[value];
  12.  
  13.     while(len)
  14.     {
  15.     if ( ((UDINT)p&3) == 0 )   /* even address*/
  16.     {
  17.     if (len > 32) /*and more than 32 bytes to fill */
  18.     {
  19.     *((UDINT*)p)++ = longValue;   /* error*/
  20.         *((UDINT*)p)++ = longValue;   /* error*/
  21.         *((UDINT*)p)++ = longValue;   /* error*/
  22.         *((UDINT*)p)++ = longValue;   /* error*/
  23.         *((UDINT*)p)++ = longValue;   /* error*/
  24.         *((UDINT*)p)++ = longValue;   /* error*/
  25.         *((UDINT*)p)++ = longValue;   /* error*/
  26.         *((UDINT*)p)++ = longValue;   /* error*/
  27.     len-=32;
  28.         continue;
  29.  
  30.     }
  31.  
  32.    }   
  33.  
  34.          *(USINT*)p++ = (USINT)longValue;  /* error*/
  35.          len--;
  36.     }
  37. }
  38.  
  39. #endif
Jun 2 '20 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 260
lvalue needs to be present on the left-hand side of the = operator.

If the aim is to assign value to a pointer, it needs to be initialized first.

Edit: Explain what you're trying to achieve and always provide sufficient code so that the other party can reproduce the same error.
Jun 2 '20 #2

Expert 100+
P: 2,418
Lines 19-26 and 34 have the increment (++) operator. Which do you intend to increment -- pointer p or the thing pointed at by p? Will the tricky looking parentheses and cast achieve your intention?
Notice that argument p is a void*. That means the compiler doesn't know the type of the thing pointed at by p, so it doesn't know the size of the thing pointed at by p, so it doesn't know how much to increment the pointer by. The code tries to get around that by casting p to a UDINT* and then a USINT*. The errors suggest the compiler is not satisfied by this tactic.

Try getting rid of the casts:
Expand|Select|Wrap|Line Numbers
  1. ...
  2.     UDINT *udp = (UDINT*)p;
  3.     *udp++ = longValue;
  4.     ...
  5.     *udp++ = longValue;
  6.     p = (void*)udp;
  7.     ...
  8.     USINT *usp = (USINT*)p;
  9.     *usp++ = (USINT)longValue;
  10.     p = (void*)usp;
  11.  
I show casts for the udp, usp, and p assignments. C does not require them but I think C++ does. If you don't need them then leave them out.

By the way, line 9 casts a UDINT value into a USINT. Make sure no information is lost or corrupted by that cast. Every cast is a red flag that you're doing something tricky and risky.

By the way, line 15 should probably be casting p to a size_t.

By the way, the register keyword on line 11 probably doesn't do anything useful. I would remove it.
Jun 3 '20 #3

Post your reply

Sign in to post your reply or Sign up for a free account.