In C,
what do you call that which is separated by semicolon?
what is the difference between an expression and a statement?
Thank you. 12 1840
Martin Johansen <ma******@is.online.no> scribbled the following: In C,
what do you call that which is separated by semicolon?
what is the difference between an expression and a statement?
Don't you have a C textbook?
"That which is separated by semicolons" can be a lot of things, but in
C, it is usually a statement.
A statement is the minimum unit of executable C code that can be
executed on its own. An expression is anything that has a value.
Some expressions qualify as statements (by adding a semicolon after
them), but not all statements qualify as expressions. For example,
conditionals and loops don't.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Roses are red, violets are blue, I'm a schitzophrenic and so am I."
- Bob Wiley
Joona I Palaste wrote: Martin Johansen <ma******@is.online.no> scribbled the following: In C,
what do you call that which is separated by semicolon?
Statements are terminated by semicolons.
what is the difference between an expression and a statement?
Don't you have a C textbook? "That which is separated by semicolons" can be a lot of things, but in C, it is usually a statement. A statement is the minimum unit of executable C code that can be executed on its own. An expression is anything that has a value. Some expressions qualify as statements (by adding a semicolon after them), but not all statements qualify as expressions. For example, conditionals and loops don't.
In the term "expression statement", "expression" is an adjective.
An expression statement is a statement,
and no statements are expressions.
a = 0 is an expression.
; is a null statement
a = 0; is an expression statement
You can't do this:
if (a = 0;){}
Expressions have types and optionally, side effects.
--
pete
Joona I Palaste <pa*****@cc.helsinki.fi> writes: An expression is anything that has a value.
An expression of type `void' is also an expression, but doesn't have
a value.
Martin
In <c0**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes: Martin Johansen <ma******@is.online.no> scribbled the following: In C,
what do you call that which is separated by semicolon?
what is the difference between an expression and a statement?
Don't you have a C textbook? "That which is separated by semicolons" can be a lot of things, but in C, it is usually a statement.
Unless it's a declaration or an expression in a for statement. Both of
which being fairly usual...
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
>Joona I Palaste <pa*****@cc.helsinki.fi> writes: An expression is anything that has a value.
In article <cu*************@zero-based.org>
Martin Dickopp <ex****************@zero-based.org> writes:An expression of type `void' is also an expression, but doesn't have a value.
It can be argued (by carefully looking past the C standards :-) )
that an expression of type "void" has one possible value. If we
compare this with a single unsigned bit -- such as in a bitfield
-- which can have two different values, namely 0 and 1, we can
conclude that the single possible value of type "void" is probably
stored in *no* bits.
The next question that would arise is "what is this single value
of type void that any expression of type void has?" -- and the
answer is "it does not matter". Whatever that value is, all void
expressions have it, so there is no need to print or input them;
all we need to know is the type. Since we never need to printf
or scanf it, we do not need conversion specifiers; and although
C prohibits both:
void a, b; /* error -- objects a and b cannot have type void */
...
a = b; /* error -- cannot assign a value of type void */
one might argue that this *should* be allowed (though since a and b
use no storage, no code would be generated :-) ).
Finally, to make it all work, we should initialize b first:
b = (void)0; /* or indeed (void)any_valid_expr */
which has the effect of converting the value to no bits, then assigning
no bits to the no-bit-storage-area named "b". :-)
(This is not quite the way C does it, though. It might be nice
just for consistency, but note that sizeof(void) would be 0, which
brings up the whole "zero-sized objects" issue that Doug Gwyn
proposed handling for C89. He was unable to gather sufficient
interest and C ended up prohibiting zero-sized objects.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Chris Torek <no****@torek.net> writes: Joona I Palaste <pa*****@cc.helsinki.fi> writes: An expression is anything that has a value. In article <cu*************@zero-based.org> Martin Dickopp <ex****************@zero-based.org> writes:An expression of type `void' is also an expression, but doesn't have a value.
It can be argued (by carefully looking past the C standards :-) ) that an expression of type "void" has one possible value. If we compare this with a single unsigned bit -- such as in a bitfield -- which can have two different values, namely 0 and 1, we can conclude that the single possible value of type "void" is probably stored in *no* bits.
I like your way of thinking along the lines of "an object of n bits can
have 2 to the power n values". :) However, as you most likely are
aware, the standard explicitly states (in 6.2.5#19) that "[t]he void
type comprises an empty set of values; [...]."
The next question that would arise is "what is this single value of type void that any expression of type void has?" -- and the answer is "it does not matter".
IMHO, in this hypothetical language where `void' has a single value,
the value should definitely be 0. :)
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Martin Johansen wrote: In C,
what do you call that which is separated by semicolon?
A clause.
According to the American Heritage Dictionary of the English Language: http://www.bartleby.com/61/16/S0251600.html
semicolon
NOUN: A mark of punctuation ( ; ) used to connect
independent clauses and indicating a closer relationship
between the clauses than a period does.
clause
NOUN:1. Grammar A group of words
containing a subject and a predicate
and forming part of a compound or complex sentence.
What is the difference between an expression and a statement?
expression
NOUN:3. Mathematics A symbol or combination of symbols
that represents a quantity or a relationship between quantities.
statement
NOUN:2. Something stated; a declaration. 6. Computer Science
An elementary instruction in a programming language.
declaration
NOUN:1. An explicit, formal announcement either oral or written.
In C, the clauses are declarations, definitions, expressions or
imperatives. Imperatives are executable statements (commands)
which change the program state.
Chris Torek <no****@torek.net> spoke thus: It can be argued (by carefully looking past the C standards :-) ) that an expression of type "void" has one possible value. (snipped)
Gee, you make me wish that C had left a place for the eternal
nothingness that is The Void! Although that would probably take it
out of the realm of programming and make C a philisophical
construct...
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
In article <c1**********@chessie.cirr.com> Christopher Benson-Manica <at***@nospam.cyberspace.org> writes: Chris Torek <no****@torek.net> spoke thus: It can be argued (by carefully looking past the C standards :-) ) that an expression of type "void" has one possible value. (snipped)
Gee, you make me wish that C had left a place for the eternal nothingness that is The Void! Although that would probably take it out of the realm of programming and make C a philisophical construct...
Actually in Algol 68 there was indeed one possible value for objects
of type 'void'. It even had a notation: 'empty'. So:
'void' i = 'empty';
was a perfectly legal declaration. Whether there is any sense in it
is something different.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
"Dik T. Winter" <Di********@cwi.nl> wrote in message news:<Ht********@cwi.nl>... In article <c1**********@chessie.cirr.com> Christopher Benson-Manica <at***@nospam.cyberspace.org> writes: > Chris Torek <no****@torek.net> spoke thus: > > It can be argued (by carefully looking past the C standards :-) ) > > that an expression of type "void" has one possible value. > > (snipped) > > Gee, you make me wish that C had left a place for the eternal > nothingness that is The Void! Although that would probably take it > out of the realm of programming and make C a philisophical > construct...
Actually in Algol 68 there was indeed one possible value for objects of type 'void'. It even had a notation: 'empty'. So: 'void' i = 'empty'; was a perfectly legal declaration. Whether there is any sense in it is something different.
Not perfectly legal; the Revised Report says in 2.1.3.1(h):
h) The only "void value" is "empty". Its mode is 'void'.
{The elaboration of a construct yields a void value when no more useful
result is needed. Since the syntax does not provide for void-variables,
void-identity-declarations or void-parameters, the programmer cannot
make use of void values, except those arising from uniting {6.4 }.} http://vestein.arb-phys.uni-dortmund.../RR/rrTOC.html
You would have to write something like
'union'('int','void') i = 'empty' instead.
It had occurred to me when I read Chris Torek's post that the odd
treatment of void in C might follow from the odd treatment of void
in Algol 68; the latter, I suspect, may have been a consequence of
coercions (i.e., MORF and COMORF).
A more likely explanation in C is the desire to avoid zero-sized
objects, mentioned in Chris Torek's post, and a good reason for
that is expected behavior of pointer arithmetic; if void a[10];
were a legal declaration, then a+0==a+1==a+2... would seem to hold,
and that would be less desirable (to me) than treating void differently.
(If void *p=&a[0]; void *q=&a[5]; what would q-p be?)
(Or if sizeof(void) is not 0, then what would be the point?)
I suppose complaints from the compiler when you dereference a void *
might also be a good thing.
--
MJSR
In article <64**************************@posting.google.com > ra*****@MailAndNews.com (MJSR) writes: "Dik T. Winter" <Di********@cwi.nl> wrote in message news:<Ht********@cwi.nl>...
.... Actually in Algol 68 there was indeed one possible value for objects of type 'void'. It even had a notation: 'empty'. So: 'void' i = 'empty'; was a perfectly legal declaration. Whether there is any sense in it is something different.
Not perfectly legal; the Revised Report says in 2.1.3.1(h):
h) The only "void value" is "empty". Its mode is 'void'.
{The elaboration of a construct yields a void value when no more useful result is needed. Since the syntax does not provide for void-variables, void-identity-declarations or void-parameters, the programmer cannot make use of void values, except those arising from uniting {6.4 }.}
http://vestein.arb-phys.uni-dortmund.../RR/rrTOC.html
I will look at the different versions of the report I have (there are at
least 6, of which 4 are preliminary). The Revised Report differs
considerably from the initial Report.
It had occurred to me when I read Chris Torek's post that the odd treatment of void in C might follow from the odd treatment of void in Algol 68; the latter, I suspect, may have been a consequence of coercions (i.e., MORF and COMORF).
Offhand I think the odd treatment in Algol 68 came in the Revised
Report, but I will have a look.
A more likely explanation in C is the desire to avoid zero-sized objects,
Although I think that C's void comes from the same in Algol 68, the
initial use in C was only to discard values, nothing more. Later
came its dual purpose (which does not come from Algol 68) in pointers.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert Brewer |
last post by:
> > > Can we insert conditional expressions in the
> decorator list ?
> >
> > Not with the current patch; however, that option may be
> allowed in the future.
>
> "In the future"...
|
by: Mike Berger |
last post by:
I'm trying to do the following switch statement
switch i {
case '> 1':
break;
case '=1':
break;
case '<1':
break;
}
|
by: Kevin Rollo |
last post by:
I'm playing with a generic routine to export data, the concept is to have a
list of data driven templates defining what fields to output.
Evaluating a simple variable field name in the function...
|
by: Raghavendra R A V, CSS India |
last post by:
hie..
Do any one knows how to write a C program without using the
conditional statements if, for, while, do, switch, goto and even
condotional statements ? It would be a great help for me if...
|
by: David Cleaver |
last post by:
Hello all,
I was wondering if there were some sort of limitations on the "if"
statement? I'm writing a program which needs to check a bunch of
conditions all at the same time (basically). And...
|
by: Fredrik Tolf |
last post by:
Take a look at this C snippet:
#include <stdio.h>
int test(int *var)
{
return(*var += 5);
}
int main(void)
|
by: Neroku |
last post by:
Hello, i would like to know what the serious definition of statements
and expressions is:
i know an expression are evaluated to a value, i.e:
1 == 2
5+7
foo( 1,2)
and a statement is...
|
by: Dave |
last post by:
I am trying to create one RegEx pattern, something like,
\s*(?<typename>\S*){1}\s*(?<varname>\S*){1}\s*{1}\s*(?<varvalue>.*)*
out of the following 2 expressions and am not having much luck.
...
|
by: =?Utf-8?B?WFNsZXI=?= |
last post by:
I have some code that works fine, except for the fact that it has a lot of
embedded if statements. I don't think that this would be practice code, but I
wanted to tap into the knowledge of this...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |