Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Definition of expression and statement.

Reply
Thread Tools

Definition of expression and statement.

 
 
James Kuyper
Guest
Posts: n/a
 
      01-02-2008
somenath wrote:
....
> I would like to clarify my self why I requested so. I was reading one
> C text book which is famous in our country it says as mentioned.
>
>
> "These instructions increase directly specify the required information
> so help in faster execution. 'C' makes
> efficient use of this feature by providing compound statements for
> which translation can be done directly to
> its corresponding machine instruction. For example:

....
> So according to this logic first function "int three_more(int x)"
> may be faster then the "int better_three_more(int x)". Is it not
> correct ?


The text you cite is describing the difference between a=a+10 and a+=10.
The difference between three_more and better_three_more is that one uses
return x+=3; and the other uses return x+3, which is a quite different
issue.

The first pair of expression are semantically equivalent, and will
compile to the same code using a smart compiler; the second of the two
expressions may compile to better code when using a dumb compiler, but
that's a minor issue. The facts that a+=10 is marginally easer to type
and easier to understand (once you're used to it) is far more important
(this is even more important when 'a' is replaced by a long complicated
expression).

The difference between return x+=3; and return x+3; is that the first
nominally specifies a pointless change to a variable whose lifetime will
end before the changed value ever gets used. A smart compiler will
probably notice that fact and produce the same code for both statements.
However, it's still bad practice to use return x+=3; because a
maintenance programmer is likely to waste time wondering why you
specified the change to x, before realizing that it was just a coding error.
 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      01-03-2008
manisha wrote:
>
> On Dec 30, 1:53 am, dspfun <(E-Mail Removed)> wrote:
> > Hi!
> >
> > The words "expression" and "statement" are often used in C99 and C-
> > textbooks, however, I am not sure of the clear defintion of these
> > words with respect to C.
> >
> > Can somebody provide a sharp defintion of "expression" and
> > "statement"? What is the difference between an expression and a
> > statement?
> >
> > This is what I have found (textbooks and own conclusions), please
> > correct if/where wrong.
> >
> > -------------------------------------------------
> > An expression is:
> > An expression contains data or no data.
> > Every expression has a type and,
> > if the type is not a void, a value.


Only if the expression is of an object type,
does it have a value.

> > An expression can contain zero or more operands, and zero or more
> > operators.


> hello,
> an expression is a combination of one or more operators,


The original "zero or more operands"
is a better description.

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Automagic determination of definition based on definition location. Jon Slaughter C++ 4 10-26-2005 05:00 PM
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM
help?: incomplete definition with complete definition in scope Ark C Programming 1 08-07-2004 04:21 PM



Advertisments