473,804 Members | 3,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

volatile expression

Given this code:

extern volatile unsigned char v;

int main(void)
{
v;

return 0;
}

My understanding is that that "v;" is an expression statement which
should be "evaluated" as a void expression for side effects, but that
"evaluation " requires an operator. Does changing the statement to

v + 0;

or

(v);

change this?

I have some compilers which do and some compilers which do not access
"v" with the above code.

--
John W. Temples, III
Nov 14 '05
14 2086
Keith Thompson <ks***@mib.or g> writes:
John Temples <us****@xargs-spam.com> writes:

My understanding is that that "v;" is an expression statement which
should be "evaluated" as a void expression for side effects,


[...]

Why do you think that evaluation requires an operator?

There is a flaw in the standard's definiion of "expression ".
C99 6.5p1 says:

An _expression_ is a sequence of operators and operands that
specifies computation of a value, or that designates an object or
a function, or that generates side effects, or that performs a
combination thereof.

which, taken literally, implies that v is not an expression, since it
contains no operators or operands.


It seems true that "v" by itself is an operand, and specifies
computation of a value. Consider

return v;

It also seems true that "v" is a sequence of { operators, operands },
if you get my meaning. So although the wording is a little funny,
the language here could be read to say that "v;" is an expression
and so must be evaluated.
Nov 14 '05 #11
Tim Rentsch <tx*@alumnus.ca ltech.edu> writes:
Keith Thompson <ks***@mib.or g> writes:
John Temples <us****@xargs-spam.com> writes:
>
> My understanding is that that "v;" is an expression statement which
> should be "evaluated" as a void expression for side effects,
[...]

Why do you think that evaluation requires an operator?

There is a flaw in the standard's definiion of "expression ".
C99 6.5p1 says:

An _expression_ is a sequence of operators and operands that
specifies computation of a value, or that designates an object or
a function, or that generates side effects, or that performs a
combination thereof.

which, taken literally, implies that v is not an expression, since it
contains no operators or operands.


It seems true that "v" by itself is an operand, and specifies
computation of a value. Consider

return v;


An operand is defined, in C99 6.4.6p2, as "an entity on which an
operator acts". return is not an operator.
It also seems true that "v" is a sequence of { operators, operands },
if you get my meaning. So although the wording is a little funny,
the language here could be read to say that "v;" is an expression
and so must be evaluated.


If there's no operator, there's no operand.

To be clear, there is no doubt in my mind that "v" by itself is
(intended to be) an expression. My quibble is with the wording of the
standard's definition; the intent is clear.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #12
Keith Thompson <ks***@mib.or g> writes:
Tim Rentsch <tx*@alumnus.ca ltech.edu> writes:
Keith Thompson <ks***@mib.or g> writes:
John Temples <us****@xargs-spam.com> writes:
>
> My understanding is that that "v;" is an expression statement which
> should be "evaluated" as a void expression for side effects,

[...]

Why do you think that evaluation requires an operator?

There is a flaw in the standard's definiion of "expression ".
C99 6.5p1 says:

An _expression_ is a sequence of operators and operands that
specifies computation of a value, or that designates an object or
a function, or that generates side effects, or that performs a
combination thereof.

which, taken literally, implies that v is not an expression, since it
contains no operators or operands.


It seems true that "v" by itself is an operand, and specifies
computation of a value. Consider

return v;


An operand is defined, in C99 6.4.6p2, as "an entity on which an
operator acts". return is not an operator.


If I'm not mistaken, 6.4.6p2 also says "other forms of operators also
exist in some contexts".

Is "v" by itself an expression? 6.5.1p2, "An identifier is a primary
expression, provided it has been declared as designating an object
[...]".

Does the appearance of "v" in a return statement make it an
expression? 6.8p2, "A full expression is an expression that is not
part of another expression or declarator. Each of the following is a
full expression: an initializer; the expression in an expression
statement; the controlling expression of a selection statement ('if'
or 'switch'); the controlling expression of a 'while' or 'do'
statement; each of the (optional) expressions of a 'for' statement;
the (optional) expression in a 'return' statement.

It also seems true that "v" is a sequence of { operators, operands },
if you get my meaning. So although the wording is a little funny,
the language here could be read to say that "v;" is an expression
and so must be evaluated.


If there's no operator, there's no operand.


If the notion of operator in 6.4.6p2 were defined exhaustively then it
might be reasonable to conclude that there's no operator. But it's
specifically not exhaustive.

What follows 'return' _is_ an expression; hence the "v" must be an
operand (unless you want to argue that "v" is an operator :); hence
there must be an operator. We can only conclude that the operator
here is one of the "other forms of operators [that] also exist in some
contexts".

Don't get me wrong, I think the wording is poor. But the language
does allow us to conclude that (in an appropriate context) an
identifier by itself is indeed an expression.

Nov 14 '05 #13
Tim Rentsch <tx*@alumnus.ca ltech.edu> writes:
Keith Thompson <ks***@mib.or g> writes:
Tim Rentsch <tx*@alumnus.ca ltech.edu> writes:
> Keith Thompson <ks***@mib.or g> writes:
>> John Temples <us****@xargs-spam.com> writes:
>> >
>> > My understanding is that that "v;" is an expression statement which
>> > should be "evaluated" as a void expression for side effects,
>>
>> [...]
>>
>> Why do you think that evaluation requires an operator?
>>
>> There is a flaw in the standard's definiion of "expression ".
>> C99 6.5p1 says:
>>
>> An _expression_ is a sequence of operators and operands that
>> specifies computation of a value, or that designates an object or
>> a function, or that generates side effects, or that performs a
>> combination thereof.
>>
>> which, taken literally, implies that v is not an expression, since it
>> contains no operators or operands.
>
> It seems true that "v" by itself is an operand, and specifies
> computation of a value. Consider
>
> return v;
An operand is defined, in C99 6.4.6p2, as "an entity on which an
operator acts". return is not an operator.


If I'm not mistaken, 6.4.6p2 also says "other forms of operators also
exist in some contexts".


Yes, it does. Section 6.4.6 is about "punctuator s". The "other
forms" clause refers to operators that don't have the form of a single
punctuator, such as the sizeof, cast, and array indexing operators.
You're right, the definition of "operator" in C99 6.4.6p2 is
explicitly not exhaustive. That just means that there are other
things that the standard explicitly refers to as operators.
Is "v" by itself an expression? 6.5.1p2, "An identifier is a primary
expression, provided it has been declared as designating an object
[...]".

Does the appearance of "v" in a return statement make it an
expression? 6.8p2, "A full expression is an expression that is not
part of another expression or declarator. Each of the following is a
full expression: an initializer; the expression in an expression
statement; the controlling expression of a selection statement ('if'
or 'switch'); the controlling expression of a 'while' or 'do'
statement; each of the (optional) expressions of a 'for' statement;
the (optional) expression in a 'return' statement.
In "return v;", yes, v is an expression (or else the statement is
illegal). It's obviously the intent of the standard that v, by
itself, is a legal expression (assuming there's an appropriate
declaration in scope). The only problem is that the standard's
definition of "expression " doesn't correctly express this fact.

(Incidentally, the presence of "v" in "return v;" isn't what implies
that "v" is an expression, any more than the presence of "int" in
"return int;" implies that "int" is an expression. The implication
goes the other way; the fact that "v" is a valid expression implies
that "return v;" is a valid return statement.)
> It also seems true that "v" is a sequence of { operators, operands },
> if you get my meaning. So although the wording is a little funny,
> the language here could be read to say that "v;" is an expression
> and so must be evaluated.


If there's no operator, there's no operand.


If the notion of operator in 6.4.6p2 were defined exhaustively then it
might be reasonable to conclude that there's no operator. But it's
specifically not exhaustive.


If there were any indication in the standard that there's an operator
in either
v;
or
return v;
it would be reasonable to conclude that there is an operator. There
is no such indication.
What follows 'return' _is_ an expression; hence the "v" must be an
operand (unless you want to argue that "v" is an operator :); hence
there must be an operator. We can only conclude that the operator
here is one of the "other forms of operators [that] also exist in some
contexts".

Don't get me wrong, I think the wording is poor. But the language
does allow us to conclude that (in an appropriate context) an
identifier by itself is indeed an expression.


Yes, the wording is poor, but I think your suggested fix requires a
strained interpretation.

C99 6.5p1 says:

An _expression_ is a sequence of operators and operands that
specifies computation of a value, or that designates an object or
a function, or that generates side effects, or that performs a
combination thereof.

Since _expression_ is in italic type, this is the standard's
definition of the term. There is no statement that it's not
exhaustive (and if it's not exhaustive, it's not a definition). It
implies that anything that doesn't consist of "operators and operands"
is not an expression. Of course an identifier that refers to an
object is an expression, but there's no visible operator (and no
justification for assuming that there's an invisible operator), and
therefore no operand (see the definition of "operand").

I suggest that this problem should be fixed by improving the wording
of the definition of "expression ", to acknowledge explicitly that not
all expressions consist of operators and operands. You suggest
leaving the definition as it is, and inventing invisible implicit
operators (which the standard does not mention anywhere) to force
certain cases to fit the definition. Sorry, but I like my idea
better.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #14
Keith Thompson <ks***@mib.or g> wrote:

In "return v;", yes, v is an expression (or else the statement is
illegal). It's obviously the intent of the standard that v, by
itself, is a legal expression (assuming there's an appropriate
declaration in scope). The only problem is that the standard's
definition of "expression " doesn't correctly express this fact.


Most definitions are incomplete in one way or another -- check any
dictionary for numerous examples. That fact that the English definition
of "expression " in the standard misses the degerate case that's included
in the formal (BNF) definition doesn't bother me at all; I don't expect
that any reader will be seriously confused or think that the informal
definition somehow overrides the formal one. Trying to enhance the
current definition to be more complete strikes me as errant pedantry.

-Larry Jones

The living dead don't NEED to solve word problems. -- Calvin
Nov 14 '05 #15

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

Similar topics

4
5822
by: dwaach | last post by:
Hi, I have something like. struct X {}; X ox; X* pox=&ox; X*& volatile r =pox;
9
2762
by: Tim Rentsch | last post by:
I have a question about what ANSI C allows/requires in a particular context related to 'volatile'. Consider the following: volatile int x; int x_remainder_arg( int y ){ return x % y; }
8
2660
by: Tim Rentsch | last post by:
Here's another question related to 'volatile'. Consider the following: int x; void foo(){ int y; y = (volatile int) x;
5
7917
by: ben | last post by:
Hello All, I am trying to make sense of a bit of syntax, is there a guru out there that can clear this up for me. I have a buffer declared as static volatile u8 buffer; and I have a pointer to that buffer declared as
14
19375
by: google-newsgroups | last post by:
Hello, even (or because?) reading the standard (ISO/IEC 9899/1999) I do not understand some issues with volatile. The background is embedded programming where data is exchanged between main program flow and interrupts. At the organisation I work, instead of declaring a variable volatile, it is casted to volatile when necessary:
17
2355
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object)." Does that mean that in the following code, *p does not have to be evaluated since its side...
9
5830
by: d.f.s. | last post by:
In the post below, 'copy constructor?', the answers refer to an object declared as const volatile. Now I'm confused. Are those terms not mutually exclusive? const='Hey compiler! This is not going to change so generate your code based on that assumption.' volatile='Hey compiler! This is going to change so generate your code based on that assumption.'
18
21619
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use memcpy to unload the data. Do I need to specify the source data as volatile in this case? What is the correct syntax for specifying that the data pointed to by the source pointer is volatile and not the pointer itself?
94
30381
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock Statement (C# Reference) statement to serialize access. " But when is it better to use "volatile" instead of "lock" ?
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.