On Wed, 16 Apr 2008 16:56:33 -0500 (CDT) in comp.lang.c.moderated,
Dag-Erling Sm=F8rgrav <des@[EMAIL PROTECTED]
> wrote:
>Magi Su <magisu@[EMAIL PROTECTED]
> writes:
>> I am a student learning Expert C Programming.
>> One interesting topic I have found is that, which the book told me=
,
>> when we use K&R style declaration and definition of functions:
>>
>> int kandr();
>> ....
>> int kandr(p1,p2)
>> int p1; char p2;
>> {}
>>
>> the 'char' parameter p2 is promoted to 'int' while pu****ng into st=
ack;
>> however, when we use ANSI style:
>>
>> int ansi(int p1,char p2)
>> {}
>>
>> the parameter p2 is pushed as 'char'.
>
>The C standard says absolutely nothing about how function parameters=
are
>stored on the stack. In fact, it says nothing about a stack, period=
..
>The exact mechanism by which parameters are passed to functions is l=
eft
>to the implementation, and *will* vary from one processor architectu=
re
>to another, one operating system to another, and even (in extreme ca=
ses)
>one compiler to another.
Even on machines which sup****t a hardware stack, and are not register
starved (we know which architecture that is), registers are used as m=
uch
as possible, often even in unoptimized code.=20
>I would expect a lecturer or textbook in "Expert C Programming" to k=
now
>and teach this.
Pedagogical simplification for purposes of exposition.=20
>I suspect you're not getting your money's worth.
>
>Get a copy of the C standard and read up about the difference betwee=
n
>the language and the implementation, and about alignment and padding=
,
>which is the closest you'll get to the issue you're asking about.
>
>Here's one place you can get a cheap copy of the standard:
>
>http://www.amazon.co.uk/C-Standard-British-Standards-Institute/dp/04=
70845732
for some values of cheap: GBP23; .de EUR56; .ca CA$77; .com US$85.=
=20
Download an even cheaper and I believe updated PDF with TCs applied
(US$30):=20
http://webstore.ansi.org/RecordDetail.aspx?sku=3DINCITS%2fISO%2fIEC+9=
899-1999+(R2005)
--=20
Thanks. Take care, Brian Inglis =09Calgary, Alberta, Canada
Brian.Inglis@[EMAIL PROTECTED]
=09(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]=
ca)
fake address=09=09use address above to reply
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|