subroutine stack and C machine model

S

spinoza1111

Well, given the presumptions
1) a function can not execute before it has obtained its arguments
2) a function can not return a value to it's caller before it has
finished its computations.
3) a caller cannot continue ("is blocked") until the callee has returned
its value.

I can see no stack (abstract or concrete) in the above, only ordered
events.

You're blind. You fail to see the difference between "a function" and
"the invocation of a function". 1, 2, and 3 still hold:

1) a function invocation can not execute before it has obtained its
arguments
2) a function invocation can not return a value to its caller before
it has
finished its computations.
3) a function invocation that invokes another function cannot continue
("is blocked") until the callee function has returned its value

But where does a function invocation obtain its arguments? Are they
stored in the space of the calling invocation as was the case in
assembler on the main frame? But if the calling invocation calls
itself directly or indirectly the arguments of the outer invocation
are destroyed, aren't they?

I've got an idea. It's called a stack.
its value.
 
M

Moi

parallel? C99 standard 6.5.17: "The left operand of a comma operator is
evaluated as a void expression: there is a sequence point after its
evaluation. THEN [emphasis mine] the right operand is evaluated...".

Yes, the expression "fa(a+1), fa(a-1)" could be evaluated in a non-

In my example, there is no comma operator involved. The comma is the
separator between two arguments for a function call (which happen to be
function calls themselves)

Argument to a function can be evaluated in any order
(the simplest example is the famous printf("%d %d\n" , i++, i++) )

AvK
 
S

spinoza1111

r = (some condition ? fb( fa(a+1), fa(a-1) ) : a;
parallel? C99 standard 6.5.17: "The left operand of a comma operator is
evaluated as a void expression: there is a sequence point after its
evaluation. THEN [emphasis mine] the right operand is evaluated...".
Yes, the expression "fa(a+1), fa(a-1)" could be evaluated in a non-

In my example, there is no comma operator involved. The comma is the
separator between two arguments for a function call (which happen to be
function calls themselves)

Argument to a function can be evaluated in any order
(the simplest  example is the famous printf("%d %d\n" , i++, i++) )

AvK

My mistake! Thanks for the clarification. I hope this is the last time
I make this silly mistake.
 
B

Ben Bacarisse

spinoza1111 said:
Actually it does.

There's probably not much point in my saying so but no, it does not.

It is true that "optimizing compilers" can reorder operands.

I see the trouble. You think Phil was talking about re-ordering the
operands. He wasn't.
It is
true that parallelism can further shuffle operands and do two
calculations simultaneously. But these code transformations have to be
intuitionistically justified.

Therefore, Schildt was correct in speaking of the stack, and you, Ben
Bacarisse, don't know your trade.

I am not sure you know what trade I am in, but I see from this (and
from another posting) that you are sticking with your plan to be rude
and homophobic.

<snip>
 
R

Richard Bos

Phil Carmody said:
int outer() { return inner1()+inner2(); }

There's nothing to stop all three functions from being active
simultaniously. There's no order between inner1 and inner2, there's
no last in to be first out.

That, as usual, depends on whether inner1() and inner2() have side
effects. If so, the ones in inner1() must all come either before all
those in inner2(), or after all those in inner2(). They may not be
interleaved; at least, not in a way which would make a measurable
difference.

Richard
 
S

spinoza1111

spinoza1111wrote:

<snip>
)> ...
)> r = (some condition ? fb( fa(a+1), fa(a-1) ) : a;
)> ...
<snip>
) How is it possible that the "two function calls" "could" be executed
) in parallel? C99 standard 6.5.17: "The left operand of a comma
) operator is evaluated as a void expression: there is a sequence point
) after its evaluation. THEN [emphasis mine] the right operand is
) evaluated...".

That's not a comma operator, so your whole post is moot.

Poot. You are right. Major brain fart on my part. It's because I
don't regularly code in C, but it appears to me that this is also true
of guys on the C99 standards committee.

I understand that C99 avoids the stack by making many orders of
evaluation undefined. I still maintain however that this was done
because the standard was highjacked by vendors who above all didn't
want to have to hire compiler developers to conform to a more rigid
standard.

Had the C99 standards mavens been competent they would have FIXED the
problem of comma being both an operator and a separator in function
calls by creating a new operator meant to gradually replace comma-as-
operator given the utility of comma-as-operator. They could have used
tilde and declared that comma is legacy but can in all cases outside
function calls be replaced by tilde, but because they were the toadies
and creatures of vendors who had no "business case" for changing
compilers, they instead preserved an ugly problem which makes smart
people like me look stupid :).

Seriously, the ideal programming language heals the split between
actual intelligence and programming ability which has plagued computer
programming since its beginning, causing intelligent people to leave
the field in disgust (which I have done) and causing idiot savants to
be considered wise.

I am not trying to excuse my error. I am saying that it's created by a
far bigger mistake. C Sharp's developers got rid of comma probably
because of this problem, but I found it useful...outside of function
calls.

I also maintain that the fact that many constructs can be compiled for
fixed registers (something that we who've programmed IBM mainframe
assembler language knew) doesn't change the fact that the stack is the
most general way of explaining runtime semantics at the entry level.

The only alternative would have been for Schildt to explain everything
using a register machine, or dataflow, or "something", and this would
have confused his readers. As it is, the market indicates that most of
Schildt's readers are happy; there's a Herb Schildt Fan Club on
Facebook.
 
S

spinoza1111

r = (some condition ? fb( fa(a+1), fa(a-1) ) : a;
parallel? C99 standard 6.5.17: "The left operand of a comma operator is
evaluated as a void expression: there is a sequence point after its
evaluation. THEN [emphasis mine] the right operand is evaluated...".
Yes, the expression "fa(a+1), fa(a-1)" could be evaluated in a non-

In my example, there is no comma operator involved. The comma is the
separator between two arguments for a function call (which happen to be
function calls themselves)

Argument to a function can be evaluated in any order
(the simplest  example is the famous printf("%d %d\n" , i++, i++) )

Yes, but for most compilers, they are evaluated in some fixed order,
usually left to right. A decent standard would have canonized and
blessed this practice IMO.
 
S

spinoza1111

There's probably not much point in my saying so but no, it does not.

<snip philosophy>

Why do you hate philosophy?
I see the trouble.  You think Phil was talking about re-ordering the
operands.  He wasn't.



I am not sure you know what trade I am in, but I see from this (and
from another posting) that you are sticking with your plan to be rude
and homophobic.

OK, the functions can be evaluated in any order. The problem being
that

(1) For a given compiler the order is usually fixed

(2) Saying that the functions can be evaluated in any order isn't a
good way to teach C

As to rudeness. Every time I post here I am subject to a shitstorm of
rudeness, and those who like you don't participate, for the most part,
in the rudeness nonetheless are too cowardly to ask the perps to be
less rude. I admit error and am initially polite, but when people call
me "crazy" in a public network I fight back.

I think you are at the detail coder level one of the best programmers
here and in the past I have profited from your insights about a
language that I need to criticise but do not use much for the same
reasons I criticise it, despite the fact that circa 1990 Princeton
University had a high enough opinion of my C coding abilities to ask
me to teach it to CS majors and assist Nash.

But you have IMO two flaws. One is that you lack collegiality and
grace and the other is that you can't, at times, see the forest for
the trees.
 
S

spinoza1111

That, as usual, depends on whether inner1() and inner2() have side
effects. If so, the ones in inner1() must all come either before all
those in inner2(), or after all those in inner2(). They may not be
interleaved; at least, not in a way which would make a measurable
difference.

But what the lads are saying is that the C99 standard makes "standard"
code, with your side effects, that ran fine on old-fashioned compilers
that evaluated left to right. If you move the code from a nonstandard
legacy compiler to a standard compiler it breaks.

This penalizes programmers that had thought to save some CPU resources
by calling inner1() to do work used by inner(2) as well as return the
first parameter.
 
N

Nick Keighley


[the discussion has moved the point that in priciple different
computations can be executed in parallel]

I'm not sure if a compliant C implementation could do this, but it is
certainly permitted to reorder things. Heavy application of the As If
Rule could presumably allow parallel execution.

Consider
f (g(), h());

most Pascal implementaions would execute the functions in the order g,
h, f. Most C (or older ones anyway) would execute them in the order h,
g,f (it makes varargs functions eaier to implement).
How is it possible that the "two function calls" "could" be executed
in parallel? C99 standard 6.5.17: "The left operand of a comma
operator

there is no comma operator in the above code. The comma seperating the
arguments in a function call is not a comma operator. C overloads it's
lexemes with various semantics.
is evaluated as a void expression: there is a sequence point
after its evaluation. THEN [emphasis mine] the right operand is
evaluated...".

Yes, the expression "fa(a+1), fa(a-1)" could be evaluated in a non-
stack environment. There are probably ** very few ** code snippets
that could not be compiled to a machine with fixed registers.

But nobody, in all probability, has learnt to code C by reading a
standards manual,

I learn computer languages partly by reading the manual and partly by
writing code. I did indeed use the language standard as part of my
learning material when learning C. The C Standard is a surprisingly
readable document.
esp. not the C99 manual since its purpose was to
protect vendors.

cobblers. I haven't read the C99 Standard in detail but I don't
believe it differs vastly from the C89 one and that was quite
readable.
The stack by construction can provide the time and
space execution semantics of all possible C programs,

I don't see this,could you explain?
and to attack
Schildt for using it was just stupid when stacks are pretty basic to
Comp Sci 101 even at the uni level.

you are still failing to distinguish logical (computer science) stacks
from phyisical stacks. And you have been corrected on this so many
times you must be doing it on purpose. More Troll Points to you.
Sounds to me that you guys AP'd

AP'd?

I have a degree in computer science (actually Computational Science)
does this mean I'm over specialised?
out of CS 101 and went on to
overspecialize and never learned the basics of your trade. Passing an
AP exam is not the same thing as learning: its more monkey and
typewriter and swotting material that's soon forgot.

<snip>
 
B

Ben Bacarisse

spinoza1111 said:
Why do you hate philosophy?

I don't. I like it a lot. None of what I snipped helped explain why
you had misunderstood the matter in hand, so I cut it.
OK, the functions can be evaluated in any order. The problem being
that

(1) For a given compiler the order is usually fixed

(2) Saying that the functions can be evaluated in any order isn't a
good way to teach C

I disagree, but what has that got to do with it? You claimed that
changing f1()+f2() to f1()-f2() altered that validity of Phil's point,
but it does not. I corrected that simply because someone else might
be confused if your comment stood uncorrected.

<snip>
 
S

Seebs

What *Ben* was saying is that the order of evaluation of inner1() +
inner2() is not specified, and neither is the order of evaluation of
inner1() - inner2() or inner1() / inner2().

Ready for the irony hit?

This is one of the things where C:TCR 3rd edition is *correct* -- it
clearly indicates that order of evaluation is not defined in these cases.

So our buddy has not only gotten it wrong, but gotten it wrong in a case
where the book he's so fond of championing got it right.

-s
 
S

Seebs

That is a champion-level non-sequitur.
I am not sure you know what trade I am in, but I see from this (and
from another posting) that you are sticking with your plan to be rude
and homophobic.

Homophobic? Now you're making me regret plonking him, that sounds like it
could have ENDLESS potential for amusement.

-s
 
S

Seebs

spinoza1111 said:
(2) Saying that the functions can be evaluated in any order isn't a
good way to teach C

_C: The Complete Reference_, 3rd edition, page 56:

Order of Evaluation

The ANSI C standard does not specify the order in which the
subexpressions of an expression are evaluated. This leaves the C
compiler free to rearrange an expression to produce more optimal code.
However, it also means that your code should never rely upon the order
in which subexpressions are evaluated. For example, the expression

x = f1() + f2();

does not ensure that f1() will be called before f2().

-s
p.s.: My copy has a note in the margin next to this saying "very good!"
 
S

Seebs

cobblers. I haven't read the C99 Standard in detail but I don't
believe it differs vastly from the C89 one and that was quite
readable.

This is just his crazy talking; he's convinced that the C99 standard was
part of some elaborate thing to let vendors fire compiler developers.
I've inferred that he was at some point a compiler developer, and he blames
the new standard for employment difficulties, rather than his obvious
inability to consistently read plain English correctly.

Probably "Advance Placement" -- in the US, you can take some high school
classes which let you get college credit for particular stuff. As an
example, I took an "AP" Calculus class, and my test scores on that got me
credit for Calc I when I got to college.
I have a degree in computer science (actually Computational Science)
does this mean I'm over specialised?

You're reading this at the wrong level. You're trying to assign semantic
content to the words and assuming some kind of pattern or meaning. Just
assume that whatever your traits are, they make you less qualified than
our Fearless Leader to talk about learning C. After all, he's hugely bitter
about the injustice in the world! That makes him an expert!

FWIW, AP calc, anyway, was indistinguishable from the college-level calc
courses covering the same material. (I know this because my dad was a
math prof, and I actually sat in on one of his calc courses at least once.
The material really is the same, which is why they give credit for it.)

There is some irony, which is that for reasons not adequately explained
(my brain is pretty weird), it *never occurred to me* to try to take any
CS classes. Programming was just stuff I did for fun. So in fact, I've
never taken ANY CS classes, of any level -- I just pick stuff up as I go,
which explains why I have a much more practical "here's what works" attitude
rather than an ivory-tower one... and also why I have to look up basic
algorithms, or be hinted towards them. (I invented a nearly-correct
Bowyer-Moore once given only the information of its storage and runtime
complexities; it turns out that if you know how much space is stored, and
how long it takes to run, the data stored are fairly obvious.)

-s
 
C

Clot Hears

spinoza1111 said:
Why do you hate philosophy?

We don't, but it has no place here, and in any case your attempts at
"philosophy" are mere gabbling.

Y'know, you were born in the wrong era. In earlier times, I'm sure you,
with your minor versifying and other babblings, could have found
employment as the Fool in the court of some third-rate German princeling.
 
B

Ben Bacarisse

Seebs said:
Homophobic? Now you're making me regret plonking him, that sounds like it
could have ENDLESS potential for amusement.

'twas in another group*. I should not have brought it up here (and
you need to get out more if that's how you measure amusement!).

*ID: <[email protected]>
 
S

Seebs

'twas in another group*.

Ahh, boring.
I should not have brought it up here (and
you need to get out more if that's how you measure amusement!).

What's funny to me is the huge overlap between this guy's crazy rants and
those of another guy I had similar arguments with a while back. They're
clearly different people, but they have the same madnesses.

-s
 
S

Seebs

Ben - Why the reference to homophobia? Something about Alan Turing?

Spinny used "faggots" as an insult in a thread in another forum. From
context, it means "people who understand algorithms better than I do".

-s
 
S

spinoza1111

This is just his crazy talking; he's convinced that the C99 standard was
part of some elaborate thing to let vendors fire compiler developers.
I've inferred that he was at some point a compiler developer, and he blames
the new standard for employment difficulties, rather than his obvious
inability to consistently read plain English correctly.

No, I don't blame the C99 standard for any personal difficulties: I
was not a C compiler developer at any time. However, I think that the
total ban on discussing personal employment difficulties here is a
form of denial, because it's pretty obvious to me that most of us have
these at some time or another.
Probably "Advance Placement" -- in the US, you can take some high school
classes which let you get college credit for particular stuff.  As an
example, I took an "AP" Calculus class, and my test scores on that got me
credit for Calc I when I got to college.

These exams are overused, since they allow students to study electives
without getting a solid foundation. Evidence here is the way you treat
Schildt for using a model to teach foundations.
You're reading this at the wrong level.  You're trying to assign semantic
content to the words and assuming some kind of pattern or meaning.  Just
assume that whatever your traits are, they make you less qualified than
our Fearless Leader to talk about learning C.  After all, he's hugely bitter
about the injustice in the world!  That makes him an expert!

Well, anger is a form of energy. I take it you're not "bitter" about
the "injustice" in the world. I don't think that's anything to be
proud about.
FWIW, AP calc, anyway, was indistinguishable from the college-level calc
courses covering the same material.  (I know this because my dad was a
math prof, and I actually sat in on one of his calc courses at least once..
The material really is the same, which is why they give credit for it.)

Well, this goes a long way to explaining why you trashed Schildt. You
never sat in an intro class and saw how students are introduced to
material. I suggest on this basis alone you withdraw the post and
apologize.
There is some irony, which is that for reasons not adequately explained
(my brain is pretty weird), it *never occurred to me* to try to take any
CS classes.  Programming was just stuff I did for fun.  So in fact, I've
never taken ANY CS classes, of any level -- I just pick stuff up as I go,

This is a real smoking gun, Seebach, and I will quote you.

"I have never taken ANY computer science classes" - Peter Seebach

but yet you can embarass a hard working man who has along with his
family. For shame.

You just pick stuff up as you go, huh? This alone will put you in
court charged with libel, because lawyers love it when a person
without credentials libels a person with credentials.

"I have never taken ANY computer science classes" - Peter Seebach

Wow. Manna from heaven. Music to my ears. Open and shut case.

which explains why I have a much more practical "here's what works" attitude
rather than an ivory-tower one... and also why I have to look up basic
algorithms, or be hinted towards them.  (I invented a nearly-correct
Bowyer-Moore once given only the information of its storage and runtime
complexities; it turns out that if you know how much space is stored, and
how long it takes to run, the data stored are fairly obvious.)

"I have never taken ANY computer science classes" - Peter Seebach
 

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,990
Messages
2,570,211
Members
46,799
Latest member
Mercury_Dev

Latest Threads

Top