473,320 Members | 2,052 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,320 software developers and data experts.

Declaration

I was reading page 131 in K&R C 2nd ed. book.

In page 63,

"The commas that seperate function arguments, variables in declarations, etc
are not comma operators, and do not guarantee left to right evaluation."

and bottom of page 131 there's example of
struct rect r, *rp = &r;
also in page 216, near bottom,
int i, *pi, *const cpi = &i;

my question is if comma in declaration does not gurantee left to right
evaluation, how did in examples latter valuables declared and intialized to
value of previous valuables on same line?

couln't the *rp declared before r is declared?
Dec 31 '06 #1
6 1814

marko wrote:
I was reading page 131 in K&R C 2nd ed. book.

In page 63,

"The commas that seperate function arguments, variables in declarations, etc
are not comma operators, and do not guarantee left to right evaluation."

and bottom of page 131 there's example of
struct rect r, *rp = &r;
also in page 216, near bottom,
int i, *pi, *const cpi = &i;

my question is if comma in declaration does not gurantee left to right
evaluation, how did in examples latter valuables declared and intialized to
value of previous valuables on same line?

couln't the *rp declared before r is declared?
Because they are using a value that is a pointer to an object
and not a value of an object.

int foo = 10;

&foo; <= value of this expression is a pointer to object 'foo'
foo; <= value of this expression is the value stored in the object
'foo'

Understand?

Additionally, you are saying 'valuables' when you mean to say 'value'.

--
aegis

Dec 31 '06 #2
ahh.. not really
I was baffled by order..

um..ok

if left to right evaluation is not guranteed, statement like
struct rect r, *rp=&r;
couldbe evaluated order below?
struct rect *rp=&r;
struct rect r;
depends on different situation since order is undefined.

instead of

struct rect r;
sturct rect *rp=&r;

the way supposed to be?
Jan 1 '07 #3
On Sun, 31 Dec 2006 14:14:26 -0500, "marko" <ma***@validnow.com>
wrote:
>I was reading page 131 in K&R C 2nd ed. book.

In page 63,

"The commas that seperate function arguments, variables in declarations, etc
are not comma operators, and do not guarantee left to right evaluation."

and bottom of page 131 there's example of
struct rect r, *rp = &r;
also in page 216, near bottom,
int i, *pi, *const cpi = &i;

my question is if comma in declaration does not gurantee left to right
evaluation, how did in examples latter valuables declared and intialized to
value of previous valuables on same line?

couln't the *rp declared before r is declared?
Even though the comma is not a comma operator, section 6.2.1-4 states
that the scope of an identifier is determined by the placement of its
declaration. 6.2.1-7 states that the scope begins just after the
completion of its declarator. The comma marks the end of the
declaration of r and the start of rp. r is therefore in scope at the
time rp is declared and the compiler is not allowed reverse the order.
Remove del for email
Jan 1 '07 #4
Barry Schwarz wrote:
On Sun, 31 Dec 2006 14:14:26 -0500, "marko" <ma***@validnow.com>
wrote:
I was reading page 131 in K&R C 2nd ed. book.

In page 63,

"The commas that seperate function arguments, variables in declarations, etc
are not comma operators, and do not guarantee left to right evaluation."

and bottom of page 131 there's example of
struct rect r, *rp = &r;
also in page 216, near bottom,
int i, *pi, *const cpi = &i;

my question is if comma in declaration does not gurantee left to right
evaluation, how did in examples latter valuables declared and intialized to
value of previous valuables on same line?

couln't the *rp declared before r is declared?

Even though the comma is not a comma operator, section 6.2.1-4 states
that the scope of an identifier is determined by the placement of its
declaration. 6.2.1-7 states that the scope begins just after the
completion of its declarator. The comma marks the end of the
declaration of r and the start of rp. r is therefore in scope at the
time rp is declared and the compiler is not allowed reverse the order.
Additionally, 6.8p3 states that initializers of automatic variables are
evaluated in the order they appear meaning that the following code must
result in x being assigned the value of 0 and y being assigned the
value of 1 and not vice versa:

int f(void) {static int i; return i++;}
int main (void) {
int x=f(), y=f();
return 0;
}

Since there is no sequence point between the declarators though, the
following would be undefined:

int i = 1;
int x = i++, y = i++;

Robert Gamble

Jan 1 '07 #5
Robert Gamble wrote:
Since there is no sequence point between the declarators though, the
following would be undefined:

int i = 1;
int x = i++, y = i++;
N1124, 6.8 Statements and blocks
....
4 ... Each of the following is a full expression: an initializer; ...
The end of a full expression is a sequence point.

--
Dietmar Schindler
Jan 5 '07 #6
Dietmar Schindler wrote:
Robert Gamble wrote:
Since there is no sequence point between the declarators though, the
following would be undefined:

int i = 1;
int x = i++, y = i++;

N1124, 6.8 Statements and blocks
...
4 ... Each of the following is a full expression: an initializer; ...
The end of a full expression is a sequence point.
I stand corrected.

Robert Gamble

Jan 5 '07 #7

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

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
8
by: newmans | last post by:
Perhaps one of the experts can straighten me out on this point... In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition, section 4.9, indicates that typedef complex<short>...
10
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as...
25
by: venky | last post by:
Hi main() { int x; /* it declaration or defination??*/ }
4
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
2
by: Alan | last post by:
Does a template class declaration, like template <class T> have to come immediately prior to the declaration of the function, e.g., T do_something (T something) { . . . } that uses it?
15
by: vaib | last post by:
hi to all.i'd like to know the actual difference between variable declaration and definition.it would be very helpful if anyone out there wud help me out with this thing.i'm writing here after here...
6
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
10
by: tvnaidu | last post by:
I am using Three pthread functions below, I got ISO error, then I declared int variable called val123, then I assigned, but still I am getting error, any idea?. also I included pthread.h. compiling...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
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...
1
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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
0
isladogs
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...

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.