473,387 Members | 1,597 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.

C Expressions

Hi,
I have doubt in C expressions. The ++, -- ( both post and
pre increment and decrement operators) have similar functionality. The
thing is if the ++ comes before an operand, it is a prefix expression.
If it comes after an operand, it is a postfix expression.

But i see in the precedence table, that

a++ and a-- comes in the category postfix operators (and have high
precedence than ++a,--a), where as
++a and --a comes in the category unary operators( with low precedence)

Why is that distinction ? Both belong to the same category,
right ?

Also what does it mean to say that the result of a++ or ++a
is not an lvalue.

Regards,
Sarathy

Jul 18 '06 #1
8 1290
On 18 Jul 2006 01:06:56 -0700, in comp.lang.c , "sarathy"
<sp*********@gmail.comwrote:
>Hi,
But i see in the precedence table, that

a++ and a-- comes in the category postfix operators (and have high
precedence than ++a,--a), where as
++a and --a comes in the category unary operators( with low precedence)

Why is that distinction ?
They have different semantics. postfix ++ doesn't change the value of
what it increments till AFTER it has been read whereas prefix ++ reads
it before the increment.:
>Both belong to the same category, right ?
No, since they have different effects.
Also what does it mean to say that the result of a++ or ++a
is not an lvalue.
More or less, it means its not an object you can assign to. If you
think about it
x++ = 34;
can't make any sense.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 18 '06 #2
sarathy wrote:
Hi,
I have doubt in C expressions.
That's interesting. I have great confidence in C expressions. They tend
to do what I ask them to do. They are very reliable.

(Hint: learn what the word "doubt" means. It does not mean the same as
"question". Your sentence would be better expressed as "I have a
question about C expressions.")
The ++, -- ( both post and
pre increment and decrement operators) have similar functionality. The
thing is if the ++ comes before an operand, it is a prefix expression.
If it comes after an operand, it is a postfix expression.

But i see in the precedence table, that

a++ and a-- comes in the category postfix operators (and have high
precedence than ++a,--a), where as
++a and --a comes in the category unary operators( with low precedence)

Why is that distinction ? Both belong to the same category,
right ?
No. As you found, they don't belong to the same category.
Also what does it mean to say that the result of a++ or ++a
is not an lvalue.
lvalues are expressions that refer to an object in memory. They are
called "left values" because they may appear on the left side of an
assignment expression.

The result of a++ or ++a is just a value. It's an ephemeral thing - it
can be used in computation, but it will not be stored anywhere. It does
not refer to an object in memory.

--
Simon.
Jul 18 '06 #3
Simon Biber wrote:
sarathy wrote:
>Hi,
I have doubt in C expressions.

That's interesting. I have great confidence in C expressions. They tend
to do what I ask them to do. They are very reliable.

(Hint: learn what the word "doubt" means. It does not mean the same as
"question". Your sentence would be better expressed as "I have a
question about C expressions.")
I am led to understand that `doubt` is idiomatic Indian English for
`question`.

I trust you will not castigate me for my use of the term `pavement`.

(Yes, it -- the former -- grates on me too.)

--
Chris "skeptic but not doubter" Dollin
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/

Jul 18 '06 #4

sarathy wrote:
Hi,
I have doubt in C expressions. The ++, -- ( both post and
pre increment and decrement operators) have similar functionality. The
thing is if the ++ comes before an operand, it is a prefix expression.
If it comes after an operand, it is a postfix expression.

But i see in the precedence table, that

a++ and a-- comes in the category postfix operators (and have high
precedence than ++a,--a), where as
++a and --a comes in the category unary operators( with low precedence)

Why is that distinction ? Both belong to the same category,
right ?
No, because the prefix and postfix forms are evaluated differently.
Also what does it mean to say that the result of a++ or ++a
is not an lvalue.
Basically, it means that it cannot be the target of an assignment, so
expressions like

x++ = 1

are illegal.

Jul 18 '06 #5
On Tue, 18 Jul 2006 13:30:58 +0100, in comp.lang.c , Chris Dollin
<ch**********@hp.comwrote:
>Simon Biber wrote:
>sarathy wrote:
>>Hi,
I have doubt in C expressions.

That's interesting. I have great confidence in C expressions. They tend
to do what I ask them to do. They are very reliable.

(Hint: learn what the word "doubt" means. It does not mean the same as
"question". Your sentence would be better expressed as "I have a
question about C expressions.")

I am led to understand that `doubt` is idiomatic Indian English for
`question`.
It is, but its probably still worth pointing out the idiomatic
International English word too. My experience with my colleagues in
our india dev team is that they welcome anything which helps them
communicate more fluently.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 18 '06 #6
Mark McIntyre wrote:
[... pre- versus post- increment/decrement ...]
They have different semantics. postfix ++ doesn't change the value of
what it increments till AFTER it has been read whereas prefix ++ reads
it before the increment.:
<mode type="nit pick">

Not exactly.

The value of a post-increment is the value of the expression
prior to the increment. Nothing requires that the increment
take place after reading the value. Ditto for the pre-increment.
Nothing requires that the value not be read until after the
increment.

A perfectly valid interpretation of:

a = b++;

could be the equivalent of:

b = b+1;
a = b-1;

Why would one do that? Who knows? Maybe the machine code that
gets generated is more efficient on a particular platform. The
point is, it's legal.

In fact, AFAIK, if "b" is not "volatile", and is never used after
the increment, the compiler is free to not even do the increment
in the first place.

</mode>

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Jul 18 '06 #7
They have different semantics. postfix ++ doesn't change the value of
what it increments till AFTER it has been read whereas prefix ++ reads
it before the increment.:
prefix reads before the incremented ? I think it is the other way
around !!!

Jul 19 '06 #8
Chris Dollin <ch**********@hp.comwrote:
Simon Biber wrote:
sarathy wrote:
I have doubt in C expressions.
That's interesting. I have great confidence in C expressions. They tend
to do what I ask them to do. They are very reliable.

(Hint: learn what the word "doubt" means. It does not mean the same as
"question". Your sentence would be better expressed as "I have a
question about C expressions.")

I am led to understand that `doubt` is idiomatic Indian English for
`question`.
Just like "handy" is idiomatic German English for a mobile phone, yes;
but that is no reason to use it as if it were English.
I trust you will not castigate me for my use of the term `pavement`.
Not if you use it correctly to mean the paved part of the road, which
people walk on, as opposed to the macadamed or cobbled part of the road,
which vehicled travel on.

Richard
Jul 19 '06 #9

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

Similar topics

72
by: Raymond Hettinger | last post by:
Peter Norvig's creative thinking triggered renewed interest in PEP 289. That led to a number of contributors helping to re-work the pep details into a form that has been well received on the...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
5
by: jens | last post by:
I was wondering if anyone could tell be whether it's possible to instruct preg_match not to save subexpressions matches under 0, 1...n keys when using named subexpressions; I.e instruct preg_named...
7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
56
by: Luke Matuszewski | last post by:
I am designing the library, which will hidden all its functions within singleton object ... So for clients they will use it like . eg. system.getElementWithId('ruler'); At library side, i...
2
by: aarklon | last post by:
Hi all, Recently i was reading a c book which contained a section called C pitfalls. it had a paragraph on the following lines:- ...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
3
by: RobG | last post by:
There has been a discussion on the iPhone web development group where an opinion has been expressed that function expressions are bad for performance and can be avoided by using function...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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.