Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Order of passing of parameters?

Reply
Thread Tools

Order of passing of parameters?

 
 
Tagore
Guest
Posts: n/a
 
      12-24-2008
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.
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      12-24-2008
Tagore <(E-Mail Removed)> writes:

> 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.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1utchar(a[i&15]);break;}}}
 
Reply With Quote
 
 
 
 
James Harris
Guest
Posts: n/a
 
      12-24-2008
On 24 Dec, 18:08, Richard Heathfield <(E-Mail Removed)> wrote:
....
> 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
 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      12-24-2008
On Dec 24, 9:51*am, Tagore <(E-Mail Removed)> wrote:
> 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.
 
Reply With Quote
 
jameskuyper
Guest
Posts: n/a
 
      12-24-2008
James Harris wrote:
> On 24 Dec, 18:08, Richard Heathfield <(E-Mail Removed)> wrote:
> ...
> > 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.


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.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      12-25-2008
James Harris wrote:
>

.... 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.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee, Frohe Weihnachten
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      12-26-2008
On Dec 25, 1:44*am, James Harris <(E-Mail Removed)>
wrote:

> * *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.
 
Reply With Quote
 
Bartc
Guest
Posts: n/a
 
      12-26-2008
Tomás Ó hÉilidhe wrote:

> 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.

--
Bart C

 
Reply With Quote
 
Tony Quinn
Guest
Posts: n/a
 
      12-26-2008
In message <Nu35l.11462$(E-Mail Removed)> , Bartc
<(E-Mail Removed)> writes
>Tomás Ó hÉilidhe wrote:
>
>> 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.
>> 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


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!
--
The fact that a believer is happier than a sceptic is no more to the
point than the fact that a drunken man is happier than a sober one.
The happiness of credulity is a cheap and dangerous quality.
-- George Bernard Shaw (1856-1950), Preface to Androcles and the Lion
 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      12-26-2008
On Dec 26, 7:00*pm, Tony Quinn <(E-Mail Removed)> wrote:

> This from a man who insists on spelling his name in a language which has
> been all but obsolete for a couple of centuries ...



By all means go correct the errors on this page:

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

Or, if you'd prefer, in Irish:

http://ga.wikipedia.org/wiki/Gaeltacht

I myself last spoke Irish about a month and half ago... in a pub in
Southeast Asia of all places.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
Passing by const & and returning a temp vs passing by value and returningit Victor Bazarov C++ 25 03-23-2005 04:24 PM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM
In which order are files looked for when loaded/requierd - and what'sthe order of suffixes? Stephan Kämper Ruby 2 01-18-2004 02:07 PM
How to Display DropDownList with preserved order (custom order) cspoh ASP .Net Web Controls 0 07-31-2003 09:19 AM



Advertisments