sequence points and the execution model

G

George

I'm given to understand that determining order has to do with the execution
model in C.

May a C program read its own source?
--
larry

We question most of the mantras around here periodically, in case
you hadn't noticed. :)
-- Larry Wall in <[email protected]>
 
J

James Kuyper

George said:
I'm given to understand that determining order has to do with the execution
model in C.

Determining the order of what? If you're referring to the order of
evaluation of expressions, that statement is both true and relevant to
subject line, but it's so vague as to be pointless. What was your
purpose in making it?
May a C program read its own source?

Of course; it's a file like any other, and therefore can be opened by
any C program that's written to read a file, so long as you make that
file available to the program.

I'm curious - do you see any connection between this question, your
previous comment, and the Subject: header for this message? I don't.
 
S

Stephen Sprunk

Mark said:
The order of execution of statements is defined by the Standard. To a
large extent it depends on the presence of sequence points. The location
of these is defined by the language standard. Where multiple statements
occur between two given sequence points, their order of execution /may/
be defined by other sections of the standard - but if not, then the
order of execution is undefined. I believe a simple example of that
would be a comma-separated list of assignments.

Doesn't the comma operator create a sequence point, just like a semicolon?

S
 
B

Ben Bacarisse

Stephen Sprunk said:
Doesn't the comma operator create a sequence point, just like a
semicolon?

Yes, and I think it is stretching the terminology to say "where
multiple statements occur between two given sequence points" since
there is a sequence point at the end of every statement.

Of course, you can have a "comma-separated list of assignments" with
no comma operator: f(a=1, b=2, c=3);.
 
S

Stephen Sprunk

Ah! I didn't think of that case, since I'd never put an assignment
inside an argument list.
quite. I suspect that

int a,b,c;
a=1,b=2,c=3;

also counts?

No. There, you are using the comma operator, so there are sequence
points between the assignments. The comma in an argument list, however,
is not the comma operator and thus does not create a sequence point.

S
 
B

Ben Bacarisse

Mark McIntyre said:
It does, but I wasn't referring to the coma operator...

But you do below. I think you need to say exactly what mean.
I'm not so sure that's stretching the terminology.

I can't think of how multiple statements can occur between two
sequence points. I thought you were being lax using the term
"statement", but there must be some explanation. Can you give an
example so we call see what you mean?

Yes, but it is not an example of the first point since it is only one
statement.
I suspect that

int a,b,c;
a=1,b=2,c=3;


also counts?

It is certainly a comma-separated list of assignments, but it does use
the comma operator, has three sequence points (one at the end), and is
a single statement.
 
J

James Kuyper

Mark said:
It does, but I wasn't referring to the coma operator...


I'm not so sure that's stretching the terminology.

Multiple statements never occur between two given sequence points,
because every statement is separated from any preceding or following
statements by a sequence point. I presume that what you were actually
referring to was "where multiple expressions occur between two sequence
points".
quite. I suspect that

int a,b,c;
a=1,b=2,c=3;


also counts?

No, in that case the ',' character does serve as a comma operator.
 
R

Richard

Mark McIntyre said:
It was - I should have been more c-standards compliant in my language. :)


Which all just goes to show how interesting this topic can become!

"quite".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top