Order of passing of parameters?

T

Tagore

According to my C text book
"parameters are passed to a called function by pushing them on the
stack from right to left."

but in a C forum I found that order of passing of parameters are
undefined.

Which of the following statement about order of parameter passing is
correct?
1) statement given in my C text book.
2) It is undefined.
3) It is implementation defined.
 
B

Ben Pfaff

Tagore said:
According to my C text book
"parameters are passed to a called function by pushing them on the
stack from right to left."

but in a C forum I found that order of passing of parameters are
undefined.

The order of evaluation of a function's arguments is not
specified by the standard. As C99 says:

10 The order of evaluation of the function designator, the actual
arguments, and subexpressions within the actual arguments is
unspecified, but there is a sequence point before the actual
call.

The mechanism used by an implementation to pass arguments to a
function is also not specified by the standard. It is quite
possible that your implementation pushes them on a stack in
right-to-left order. Other implementations might pass some
arguments in machine registers or some completely different
mechanism.
 
J

James Harris

The formal term for situations where the implementation has free
rein to do as it likes *provided* the correct effect is achieved,
and where it doesn't has to document its choice, is "unspecified
behavior" (alas, no 'u' in "behavior" because - well, because!).

OT. I'd heard that American spelling was due to Webster (he of the
dictionary fame - remember "Morocco bound" and all that? Older readers
may) making a concious choice to educate Americans with spellings of
his own choosing.

http://en.wikipedia.org/wiki/Noah_Webster

seems to agree. (I don't know if it's true or not.) Under the heading
"Speller and dictionary" it says, in part:

Slowly, he changed the spelling of words, such that they became
'Americanized'. He chose s over c in words like defense; he changed
the re to er in words like center; he dropped one of the Ls in
traveller; at first, he kept the u in words like colour or favour, but
he dropped it in later editions.

If true it's rather annoying that someone should choose his own
opinions about how a language should be changed. As has been said
Brits and Americans are two groups of people separated by a common
tongue.

Speaking of tongue (amazing how these links are so seamless :)) the
same paragraph says

He also changed "tongue" to "tung."

I can't believe that's right.....

James
 
U

user923005

According to my C text book
 "parameters are passed to a called function by pushing them on the
stack from right to left."

but in a C forum I found that order of passing of parameters are
undefined.
Unspecified

Which of the following statement about order of parameter passing is
correct?
1) statement given in my C text book.
2) It is undefined.
3) It is implementation defined.

The closest to correct is #3, but #1 is an often true generalization
(which can get you into trouble, of course, if you think it is always
true). #2 is simply wrong.
One compiler that I have will pass the parameters three different
ways, depending upon how I request. I usually choose passing
parameters as registers where possible when I have a choice.

For most implementations, if you do not specify any special options,
the parameters will be pushed onto the stack, along with the address
of the function and any local variables. It is important to
understand this general idea so you can recognize that deeply
recursive programs may cause problems if there are a great number of
parameters and lots of large local variables and things of that
nature. However, your C book does you a disservice by making the
statement as though it were a fact that is always true.

The language itself does not even insist that C has a stack at all
(indeed, there are machines with C compilers that definitely do not
possess a hardware stack).

Here is what is crucial for you to understand about function
parameters:
In C they are all pushed by value. Even an address is passed as a
copy, so if you want to change an address that you pass you need to
pass the address of the address. The rest of the details about how
the arguments get from the caller to the function are system/compiler
specific and you will need to read and understand the documentation to
be absolutely sure that you understand how it works.
 
J

jameskuyper

James said:
OT. I'd heard that American spelling was due to Webster (he of the
dictionary fame - remember "Morocco bound" and all that? Older readers
may) making a concious choice to educate Americans with spellings of
his own choosing.

http://en.wikipedia.org/wiki/Noah_Webster

seems to agree. (I don't know if it's true or not.) Under the heading
"Speller and dictionary" it says, in part:

Slowly, he changed the spelling of words, such that they became
'Americanized'. He chose s over c in words like defense; he changed
the re to er in words like center; he dropped one of the Ls in
traveller; at first, he kept the u in words like colour or favour, but
he dropped it in later editions.

If true it's rather annoying that someone should choose his own
opinions about how a language should be changed. As has been said
Brits and Americans are two groups of people separated by a common
tongue.

Keep in mind that he wasn't making these choices in a vacuum.
Webster's choices were very influential, but only because people in
the US were in a mood to be influenced in that fashion. They were
rather angry at the Brits, and not too happy with the rest of Europe,
either (yes, I'm well aware of British attitudes toward the use of the
word "Europe" to include the British Isles - but the people I'm
describing would not have cared about that). If they'd been happy,
they wouldn't have left. Therefore, they were actively looking for
ways to distance themselves from Britain in particular, and Europe in
general. A lot of other customs were deliberately changed around the
same time, for the same reason, including even such things as the
etiquette rules for using knives and forks at formal dining occasions.
Speaking of tongue (amazing how these links are so seamless :)) the
same paragraph says

He also changed "tongue" to "tung."

I can't believe that's right.....

If he did, it didn't take; that's not the way we spell it here now.
 
C

CBFalconer

James said:
.... snip ...

OT. I'd heard that American spelling was due to Webster (he of
the dictionary fame - remember "Morocco bound" and all that?
Older readers may) making a concious choice to educate Americans
with spellings of his own choosing.

http://en.wikipedia.org/wiki/Noah_Webster

seems to agree. (I don't know if it's true or not.) Under the
heading "Speller and dictionary" it says, in part:

Slowly, he changed the spelling of words, such that they became
'Americanized'. He chose s over c in words like defense; he
changed the re to er in words like center; he dropped one of the
Ls in traveller; at first, he kept the u in words like colour or
favour, but he dropped it in later editions.

If true it's rather annoying that someone should choose his own
opinions about how a language should be changed. As has been
said Brits and Americans are two groups of people separated by
a common tongue.

Speaking of tongue (amazing how these links are so seamless :))
the same paragraph says

He also changed "tongue" to "tung."

When I was young we had a 1908 Funk & Wagnals Encyclopaedia
around. That was an American edition. It was full of 'tho',
'thru', and similar spelling revisions. I think it finally got
lost about 4 years ago when I closed down our home for the past 40
years after my wifes death, and had to be vicious. The book
collection was seriously damaged.
 
T

Tomás Ó hÉilidhe

   Slowly, he changed the spelling of words, such that they became
'Americanized'. He chose s over c in words like defense; he changed
the re to er in words like center; he dropped one of the Ls in
traveller; at first, he kept the u in words like colour or favour, but
he dropped it in later editions.



At the moment I'm teaching English to Lao kids, and the English
writing system is an absolute pain in the ass for teaching. The
English writing system is such an embarrassment that we actually have
"spelling bees", it's actually an /accomplishment/ to be able to spell
stuff properly in English!

When I'm teaching I might write a sentence like:

I eat fish every day

And then write:

I ate fish yesterday

but they haven't got a clue how to say it. The "vowel after the next
consonant" thing really screws things up, such as:

hope Versus hop
hoping Versus hopping

And then you have just plain inconsistency:

steak Versus peak

And you have the two "th" sounds, both voice and unvoiced, represented
by the same symbol:

thanks
them

And you have the ambiguity of whether S is pronounced as an S or a Z,
and whether C is pronounced as K or S.

It's almost embarrassing to have to tell them that English speakers
pretty much memorise how to spell words. There about about two weeks
ago a Lao person was trying to tell me in the Lao language that he
sewed his own hand supports for weightlifting, but I didn't understand
him so I got out a dictionary; I looked up the word he said and found
that it meant "sew", and then he asked me how to spell it in English,
and all I could say was "S - E - W, yes it makes no sense, just
memorise it.".

A lot of the time when I'm teaching and writing on the board I'll
rewrite the word using the Lao writing system, which is 100% phonetic.
Even if I were to rewrite it using the English writing system, e.g. by
changing "through" to "thru", it would still be ambiguous a lot of the
time.

The only thing that keeps the current English writing system alive is
eliteness. Now that I've experienced a language that has a brilliant
writing system, I'd definitely be in favour of revamping written
English. It would have three benefits:
1) Our kids would have less trouble learning it
2) Foreign adults would have less trouble learning English
3) Native adults who have bad spelling skills would have less trouble

Has anyone ever encountered a writing system that works on a
"consonant + vowel pair" system? In the Lao writing system, you always
have a "consonant + vowel pair" at the start of a syllable. If a
syllable doesn't start with a consonant, then they have a symbol for a
silent consonant. It's because of this that they can write without
putting spaces between words, because they always know whether a
particular consonant is the end of the previous syllable or the
beginning of the next syllable (if it's the end of the previous
syllable then it won't have a vowel after it). Given the "consonant +
vowel pair" system, and given that the written language is 100%
phonetic (you always know how to say a word when you read it), it's
got to be one of the best writing systems in the world. You can master
it in just a week or two if you're diligent enough.


If true it's rather annoying that someone should choose his own
opinions about how a language should be changed. As has been said
Brits and Americans are two groups of people separated by a common
tongue.



That's a load of nonsense. The differences between British and
American English take only a few seconds to resolve. Take the
following:

- James is after cutting his knee, have you got a plaster?
- A plaster... what's a plaster?
- To put on his knee to cover the wound
- Oh you mean a band-aid
- What, a band-aid?
- Yeah we call it a band-aid

Other examples are "sweater" instead of "jumper", "sneakers" instead
of "runners", "sidewalk" instead of "path", but again these only take
a few seconds to resolve. If you were to sit down for half an hour and
read an article on differences between American and British English
vocabulary, you'd be flying.

European native English speakers are already aware of words such as
"sweater" from watching US television; but they don't use these words
themselves. It doesn't go the other way though, Americans tend to not
have a clue about British words like "jumper". The situation is
similar between Lao and Thailand; Lao people can speak and read Thai
just fine from watching Thai television, but Thai people don't know
Lao words.
 
B

Bartc

Tomás Ó hÉilidhe said:
At the moment I'm teaching English to Lao kids, and the English
It's almost embarrassing to have to tell them that English speakers
pretty much memorise how to spell words.
A lot of the time when I'm teaching and writing on the board I'll
rewrite the word using the Lao writing system, which is 100% phonetic.

In Europe languages which use a phonetic written language tend to make up
for it's simplicity by having a horrendous grammar.
Even if I were to rewrite it using the English writing system, e.g. by
changing "through" to "thru", it would still be ambiguous a lot of the
time.

I think some shorthand systems for English use phonetics too. But...
The only thing that keeps the current English writing system alive is
eliteness.

For everyday use a phonetic written English would have even more ambiguities
than there already are.

And because of the current wideranging ways of actually pronouncing English
(think of US, Australian, and UK regions) who would decide what the official
phonetics should be?
Now that I've experienced a language that has a brilliant
writing system, I'd definitely be in favour of revamping written
English. It would have three benefits:
1) Our kids would have less trouble learning it
2) Foreign adults would have less trouble learning English
3) Native adults who have bad spelling skills would have less trouble

It would be a lot less fun. I remember seeing a stern note from a shopkeeper
to his pilfering staff: "... trouble will be dealt with at sauce..."

But hang on: in your system, "source" and "sauce" would have the same
spelling anyway.
Has anyone ever encountered a writing system that works on a
"consonant + vowel pair" system?

Japanese katakana? Over there I'm Barto apparently because a consonant
/must/ be followed by a vowel.
 
T

Tony Quinn

This from a man who insists on spelling his name in a language which has
been all but obsolete for a couple of centuries ... am I glad I didn't
see his full diatribe and just the edited highlights in a response. I
suspect that it's bugger all to with the grammar and/or spelling, and
all to do with his apparent hatred of English and *THE* English.

Can you take it elsewhere and return to C, please!
 
T

Tomás Ó hÉilidhe

For everyday use a phonetic written English would have even more ambiguities
than there already are.

And because of the current wideranging ways of actually pronouncing English
(think of US, Australian, and UK regions) who would decide what the official
phonetics should be?



Just last night I was sitting a table with an American, an Australian
and a New Zealander (you get all sorts out here). The American and the
Australian pronounced "car" with a vowel similar to that in "law",
however myself and the New Zealander pronounced it with a vowel
similar to that in "bad".

The way of getting around this in a phonetic writing system is to have
a unique symbol to represent the sound of "ar", and to have this
symbol pronounced differently by different dialects. That's what the
Irish language does; for instance we have "ao", which is pronounced to
rhyme with "my" up North, and pronounced to rhyme with "may" down
South. So for instance, you could have a page of written Irish written
by a Southerner, and a Northerner will read it with a Northern accent.
Neither dialect feels as though they've gotten the shaft.
 
S

Stephen Sprunk

Tagore said:
According to my C text book
"parameters are passed to a called function by pushing them on the
stack from right to left."

but in a C forum I found that order of passing of parameters are
undefined.

Which of the following statement about order of parameter passing is
correct?
1) statement given in my C text book.
2) It is undefined.
3) It is implementation defined.

Your book is correct for some systems, but it is incorrect for others.

The mechanism by which parameters are passed to functions is unspecified
by the C standard. And, unless you're doing something really
unportable, it shouldn't matter.

<OT>
Typically, your implementation will produce programs that conform with a
particular "Application Binary Interface", which specifies this and many
other details so that code compiled with different tools (perhaps in
different languages) can be linked together and work properly. ABIs do
vary significantly, so you'd have to look up the one for your particular
implementation and see what it says. And, some implementations define
several mechanisms and when to use each, e.g. passing via registers by
default but using a stack for variadic functions, or passing
left-to-right for OS function calls but right-to-left for user function
calls.
</OT>

S
 
G

George

James said:
[1 quoted line suppressed] ... snip ...
[26 quoted lines suppressed]

When I was young we had a 1908 Funk & Wagnals Encyclopaedia
around. That was an American edition. It was full of 'tho',
'thru', and similar spelling revisions. I think it finally got
lost about 4 years ago when I closed down our home for the past 40
years after my wifes death, and had to be vicious. The book
collection was seriously damaged.

Of course you mean Funk and Wagnalls. I think it dates a person to have
used it.

As far as books go, I'm still taking your advice and burning them based on
lack of relevance to C. Most of them are from my decedent uncle, who
dropped dead in this house last year.

Yesterday was cold--I think Siberian air is seeping over to Alaska and is
making this huge low pressure system that covers the whole US--but National
Geographics were pumping out calories in my woodburner.
--
George

We know that dictators are quick to choose aggression, while free nations
strive to resolve differences in peace.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
D

Dik T. Winter

> When I was young we had a 1908 Funk & Wagnals Encyclopaedia
> around. That was an American edition. It was full of 'tho',
> 'thru', and similar spelling revisions.

Yes, those were spellings Webster favoured (note the 'ou', I learned British
English at school). You might also have noticed 'nite'. Some of his reforms
made it into the everyday spelling, some not.

Nearly every language is (I think) in its spelling influenced by a single or
only a few people. That is certainly true for Dutch, where the first
dictionary produced was very influential.
 
D

Dik T. Winter

> Has anyone ever encountered a writing system that works on a
> "consonant + vowel pair" system?

There are a lot, but they do not work well with languages that do not consist
of "consonant + vowel pair"s syllables only. They ignore consonant clusters,
something that is quite common in some languages (especially of Germanic
origin). So they do not need only a consonant suppression sign, but also
a vowel suppression sign. People accustomed to a language where between
consonants alway at least one vowel is needed are in genereal not able to
correctly pronounce the Dutch word "herfst" (autumn, four consonants at the
end) or "angstschreeuw" (five consonants in the middle, 'ng' and 'ch' are
single consonants).
 
R

Richard Bos

=?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= said:
At the moment I'm teaching English to Lao kids, and the English
writing system is an absolute pain in the ass for teaching. The
English writing system is such an embarrassment that we actually have
"spelling bees", it's actually an /accomplishment/ to be able to spell
stuff properly in English!

Amazing that this "English is _soooo_ hard" myth keeps making all you
Limeys and Yankees soooo proud.

For your information, people in other countries, speaking other
languages, have spelling contests as well. They may not always be as
simplistic as the ones you use, but we do have them.

Richard
 
L

lawrence.jones

Richard Bos said:
Amazing that this "English is _soooo_ hard" myth keeps making all you
Limeys and Yankees soooo proud.

I don't think we're particularly proud of it -- it's not significantly
more difficult for native speakers than any other language. But I feel
sorry for anyone who has to learn it as a non-native speaker since
whatever language(s) they already know will likely lead them astray as
often as provide correct guidance. That's the problem with adopting
words and phrases from every language you've ever come in contact with
with varying degrees of assimilation: whatever "rules" there are are
nowhere near universal.
 
C

CBFalconer

I don't think we're particularly proud of it -- it's not
significantly more difficult for native speakers than any other
language. But I feel sorry for anyone who has to learn it as a
non-native speaker since whatever language(s) they already know
will likely lead them astray as often as provide correct guidance.
That's the problem with adopting words and phrases from every
language you've ever come in contact with with varying degrees of
assimilation: whatever "rules" there are are nowhere near
universal.

Disagree. When I was a young sprout my parents insisted that I
take Latin in school (Yes, it was still routinely available then).
I dutifully did so for a year and a half. In the process the
teacher had to tell us things about grammar, which cleared up all
sorts of things in English (for me).

After that year and a half I wanted maths, not Latin. I got
something like marks of 8 and 16 (out of 100) for two tests, and my
parents bowed to my wishes. But I have never regretted the
exposure that I did get.
 
K

Kenny McCormack

CBFalconer said:
Disagree. When I was a young sprout my parents insisted that I
take Latin in school (Yes, it was still routinely available then).

Heck! Back then, it was spoken throughout the empire.

Anyway, as there is no mention of Latin in the C standards documents,
you, of all people, should know that this is:

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

--
Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language
 
K

Kenny McCormack

Kenny you missed the apostrophe in "can't". You just dropped 15 points on
the CLC importance scale.

It's been that way since the beginning. I wrote it that way on purpose.

P.S. You missed the comma after "Kenny".
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top