473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

invalid lvalue in increment error

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
2 1864
dev7060
636 Expert 512MB
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
donbock
2,426 Expert 2GB
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

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

Similar topics

19
by: Lucas Machado | last post by:
i'm doing some Linux Kernel hacking for a course i'm currently taking. there is a pointer to a struct (struct example_struct *ex_ptr) in a .c that i want to access in a system call. i defined a...
4
by: bob | last post by:
I have little C experience and am concurrently trying to tackle C and LKM's (a little too ambitious maybe) anyway here is the problem I'm having with an example module I found. static int...
5
by: A. Farber | last post by:
Hello, I call readv() and writev() in several spots of a program which I run under Linux, OpenBSD and Cygwin. Since it always the same way (check the return value; then check errno and retry if...
3
by: Suyash Upadhyay | last post by:
Hello all, I was writing a code regarding offset of structure elements. struct a { struct b { int i; float f; char ch; }x;
6
by: Paul Edwards | last post by:
The following code: int main(void) { char *x; (void **)x += 1; return (0); }
4
by: mdh | last post by:
May I ask why this works: given: char s; char *posbfr = s; char *endbfr = s + MAXOP; void(...){ if (posbfr >= endbfr) printf("......");
1
by: yyhkitty | last post by:
Hi, I keep getting two invalid lvalue in assignment errors. here's what my code looks like: pthread_t msg_receive(char *sbuffer, int *maxlen) { // get the values for sbuffer and maxlen ...
11
by: markryde | last post by:
Hello, Followed here is a simplified code example of something which I try to implement; in essence , I want to assign a value to a return value of a method is C. I know, of course, that in this...
3
by: ra123kesh | last post by:
while executing this code i was getting a error Invalid lvalue in assignment. Can any one tell how to correct this. dataItem* d=(dataItam*)malloc(10*sizeof(dataItem)); dataItem* temp;...
1
by: PhysKid | last post by:
Hi, am trying to program Shut the Box (http://en.wikipedia.org/wiki/Shut_the_Box). when I decide which tile to flip, I get the error " invalid lvalue in assignment". I've looked this up and it's...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.