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

?: as an lvalue

Hi Everyone,

I have the following piece of code, and i expected an error, however
i don't get an error,

int main()
{
int aa=0,b=0;
1>0?aa:b = 10;
printf("value %d %d\n",aa,b);
return(0);
}

and output is value 0 0

Thanks in advance ! ! !
Mar 30 '08
54 3107
Harald van Dijk <tr*****@gmail.comwrites:
On Wed, 02 Apr 2008 15:39:32 -0400, lawrence.jones wrote:
>Keith Thompson <ks***@mib.orgwrote:
>>Undefined behavior is illegal?

Well, the C Police aren't going to come and arrest you, but it's not
valid, which is what most people mean by "legal".

Most people don't consider the things illegal that the police turn a
blind eye towards. Undefined behaviour is what happens when your program
doesn't play by C's rules, but at the same time, C's rules tell your
compiler not to arrest you.
Actually, C's rules specifically *don't* tell the compiler not to
arrest you. Printing an error message and terminating, either at
compile time or at run time, is well within the (nonexistent) bounds
of undefined behavior.

Personally, I tend to think of anything that requires a diagnostic (a
syntax error or constraint violation) as "illegal" -- and even then it
can be "legal" in the sense that the implementation is still allowed
to produce an executable.

If everybody else thinks of UB as "illegal", I suppose I'll go along
with the consensus, but I don't think I'm the only one who finds the
usage ambiguous.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 3 '08 #51
Keith Thompson said:

<snip>
If everybody else thinks of UB as "illegal", I suppose I'll go along
with the consensus, but I don't think I'm the only one who finds the
usage ambiguous.
Is it illegal to use the extensions provided by an implementation? Is it
illegal to call functions in a third-party library? Is it illegal to talk
to another computer over a network?

It is one thing for the Standard to decline to define what will happen if
you do <foo>, but quite another to forbid you from doing it.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 3 '08 #52
la************@siemens.com wrote:
Andrey Tarasevich <an**************@hotmail.comwrote:
>In C99 array-to-pointer conversion is applied to non-lvalue arrays,
meaning that the above code becomes legal. An interesting side effect of
this change is that in C99 the following is legal as well

foo().a[1] = 5;

No, it's not:

If an attempt is made to modify the result of a function call or
to access it after the next sequence point, the behavior is
undefined.
I was talking about the syntactical legality, meaning that the above
code doesn't violate any syntax rules or constraints of C99, as opposed
to those of C89/90. This is, I believe, what the word "legal" usually
means in the context of C language (due to lack of more tightly defined
terms like ill-/well-formed in C++).

--
Best regards,
Andrey Tarasevich
Apr 3 '08 #53
On Wed, 02 Apr 2008 19:03:44 -0700, Keith Thompson wrote:
Harald van Dijk <tr*****@gmail.comwrites:
>On Wed, 02 Apr 2008 15:39:32 -0400, lawrence.jones wrote:
>>Keith Thompson <ks***@mib.orgwrote:
Undefined behavior is illegal?

Well, the C Police aren't going to come and arrest you, but it's not
valid, which is what most people mean by "legal".

Most people don't consider the things illegal that the police turn a
blind eye towards. Undefined behaviour is what happens when your
program doesn't play by C's rules, but at the same time, C's rules tell
your compiler not to arrest you.

Actually, C's rules specifically *don't* tell the compiler not to arrest
you. Printing an error message and terminating, either at compile time
or at run time, is well within the (nonexistent) bounds of undefined
behavior.
I stand by my previous statement.

void f(){}
void g(){if(0)f(1);}

This has been declared a valid translation unit, and it may appear in
strictly conforming programs. A compiler is not allowed to reject it, as
long as the call to f is never executed, and in the general case, it's
not possible for the compiler to determine whether such a call would ever
be executed.
Apr 3 '08 #54
Harald van Dijk <tr*****@gmail.comwrites:
On Wed, 02 Apr 2008 19:03:44 -0700, Keith Thompson wrote:
>Harald van Dijk <tr*****@gmail.comwrites:
>>On Wed, 02 Apr 2008 15:39:32 -0400, lawrence.jones wrote:
Keith Thompson <ks***@mib.orgwrote:
Undefined behavior is illegal?

Well, the C Police aren't going to come and arrest you, but it's not
valid, which is what most people mean by "legal".

Most people don't consider the things illegal that the police turn a
blind eye towards. Undefined behaviour is what happens when your
program doesn't play by C's rules, but at the same time, C's rules tell
your compiler not to arrest you.

Actually, C's rules specifically *don't* tell the compiler not to arrest
you. Printing an error message and terminating, either at compile time
or at run time, is well within the (nonexistent) bounds of undefined
behavior.

I stand by my previous statement.

void f(){}
void g(){if(0)f(1);}

This has been declared a valid translation unit, and it may appear in
strictly conforming programs. A compiler is not allowed to reject it, as
long as the call to f is never executed, and in the general case, it's
not possible for the compiler to determine whether such a call would ever
be executed.
Right. Since the call f(1) never occurs, there's no undefined
behavior.

Perhaps I should have been clearer about the fact that UB can cause a
translation unit to be rejected by the compiler only if it can prove
that the UB will always happen, but I didn't think it was an important
point in context.

I'm not aware of any point on which we disagree.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 3 '08 #55

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

Similar topics

19
by: Hongzheng Wang | last post by:
In K&R, they said: An object is a named region of storage; an lvalue is an expression refer to an object. How about these concept in C++? `The C++ Programming Language' has a similar...
9
by: Steven T. Hatton | last post by:
This is from the draft of the previous version of the Standard: http://www.kuzbass.ru:8086/docs/isocpp/expr.html 2- A literal is a primary expression. Its type depends on its form...
15
by: Michael Baehr | last post by:
I recently upgraded my Arch Linux system to GCC 3.4, and found out that a previously accepted behavior (cast-as-lvalue) is now marked as deprecated, and will cease to function in GCC 3.5. This has...
24
by: Romeo Colacitti | last post by:
Hi, Does anyone here have a strong understanding for the meanings of the terms "lvalue" and "rvalue" as it pertains to C, objects, and different contexts? If so please share. I've been...
9
by: junky_fellow | last post by:
Consider the following piece of code: (char *)0x100; /* I know that converting an integer to pointer type is implementation defined. But forget this for a moment */ My question is, Why the...
3
by: Kavya | last post by:
Can someone give and explain in simple terms a definition of lvalue? Also what are these modifiable and non-modifiable lvalues? I always thought that, if we can assign to anything then that...
10
by: the_init | last post by:
Hi friends, I read about Lvalue in previous posting and Googled it but I'm not understood it completely. There is a small doubt. int a; a=20; // here a is Lvalue But
14
by: nobrow | last post by:
Yes I know what lvalue means, but what I want to ask you guys about is what are all valid lvalues ... a *a a *(a + 1) .... What else?
6
by: Yarco | last post by:
I've alway thought lvalue means Left Value and rvalue means Right Value before i've read someone's article. It is said "lvalue = location value" and "rvalue = read value". Which one is right, then?
33
by: Pietro Cerutti | last post by:
Hi group, assume the following declarations: char *func_1(void); void func_2(char **); I am allowed to do: char *c = func_1();
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.