473,387 Members | 1,540 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,387 software developers and data experts.

invalid lvalue in assignment

mdh
May I ask why this works:

given:
char s[];
char *posbfr = s;
char *endbfr = s + MAXOP;

void(...){
if (posbfr >= endbfr)
printf("......");
else
*posbfr++ = c ;
}
but this is invalid?

(posbfr >= endbfr) ? printf("......") : *posbfr++ = c ;

(with an "invalid lvalue in assignment") error?

or...is this the dumbest question yet? :-)

Thank you.

Oct 28 '07 #1
4 9035
mdh wrote:
May I ask why this works:

given:
char s[];
char *posbfr = s;
char *endbfr = s + MAXOP;

void(...){
if (posbfr >= endbfr)
printf("......");
else
*posbfr++ = c ;
}
but this is invalid?

(posbfr >= endbfr) ? printf("......") : *posbfr++ = c ;
You are assigning c to the result of the conditional expression, so the
above equivalent to

((posbfr >= endbfr) ? printf("......") : *posbfr++) = c ;

--
Ian Collins.
Oct 28 '07 #2
mdh wrote:
May I ask why this works:
<snip>
but this is invalid?

(posbfr >= endbfr) ? printf("......") : *posbfr++ = c ;

(with an "invalid lvalue in assignment") error?
Assignment is lower priority than ?:. The compiler sees your expression
as (cond ? x : y) = c;

Try explicit parentheses, like this:

(posbfr >= endbfr) ? printf("......") : (*posbfr++ = c) ;
Oct 28 '07 #3
mdh
On Oct 28, 4:02 pm, Ian Collins <ian-n...@hotmail.comwrote:
mdh wrote:
but this is invalid?
(posbfr >= endbfr) ? printf("......") : *posbfr++ = c ;
Ian Collins wrote:
You are assigning c to the result of the conditional expression, so the
above equivalent to

((posbfr >= endbfr) ? printf("......") : *posbfr++) = c ;


Ian,
I know I am not then understanding this. I thought, given

expr1 ? expr2 : expr3;

then, if expr1 evaluates to true, then expr2 is evaluated, else if
false, expr3.

So, in the above case, is an assignment not regarded as a valid
expression?
..
Oct 28 '07 #4
mdh
On Oct 28, 4:03 pm, Peter Pichler <use...@pichler.co.ukwrote:
mdh wrote:
May I ask why this works:


Try explicit parentheses, like this:

(posbfr >= endbfr) ? printf("......") : (*posbfr++ = c) ;
Aha...thank you.
Oct 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
1
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL:...
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); }
3
by: vunet | last post by:
Hello, I've just installed ASPXMLRPC library and testing their main function: xmlRPC ("URL", "command_name", params) The function converts all parameters to XML, sends a request to third-...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.