Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Promotions whil...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 1076 of 1098
Post > Topic >>

Promotions while delivering parameters

by Magi Su <magisu@[EMAIL PROTECTED] > Apr 13, 2008 at 02:41 AM

Hello everyone!

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 pushing into stack;
however, when we use ANSI style:
int ansi(int p1,char p2)
{}
the parameter p2 is pushed as 'char'.

I have written a program to try it out:

------------------promote1.c----------------------
void fun1(int,char);
void fun2();

int main(void)
{
        asm(" #FUNCTION 1 CALL "); 
        fun1(1,'c');
        asm(" #FUNCTION 2 CALL "); 
        fun2(1,'c');
        asm(" #FUNCTION CALL FINISHED "); 
        return 0;
}

void fun1(int i1,char i2)
{
        asm(" #FUNCTION 1 "); 
        int i=i1+i2;
}

void fun2(i1,i2)
        int i1;
        char i2;
{
        asm(" #FUNCTION 2 "); 
        int i=i1+i2;
}


------------------------promote1.s, part----------------
#APP
         #FUNCTION 1 CALL 
        .loc 1 7 0
#NO_APP
        movl    $99, 4(%esp)
        movl    $1, (%esp)
        call    fun1
        .loc 1 8 0
#APP
         #FUNCTION 2 CALL 
        .loc 1 9 0
#NO_APP
        movl    $99, 4(%esp)
        movl    $1, (%esp)
        call    fun2
        .loc 1 10 0
#APP
         #FUNCTION CALL FINISHED 
        .loc 1 11 0
#NO_APP


From the selected part of assemble file, I found that both function call,
fun1 and fun2, have promoted the 'char' to 'int'. Could anyone explain
why?
Thanks!
-- 
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.




 8 Posts in Topic:
Promotions while delivering parameters
Magi Su <magisu@[EMAIL  2008-04-13 02:41:49 
Re: Promotions while delivering parameters
Francis Glassborow <fr  2008-04-16 16:56:02 
Re: Promotions while delivering parameters
=?utf-8?Q?Dag-Erling_Sm=C  2008-04-18 16:11:36 
Re: Promotions while delivering parameters
Francis Glassborow <fr  2008-04-21 13:20:21 
Re: Promotions while delivering parameters
=?utf-8?Q?Dag-Erling_Sm=C  2008-04-16 16:56:33 
Re: Promotions while delivering parameters
Brian Inglis <Brian.In  2008-04-18 16:11:55 
Re: Promotions while delivering parameters
Kenneth Brody <kenbrod  2008-04-16 16:56:45 
Re: Promotions while delivering parameters
=?utf-8?Q?Dag-Erling_Sm=C  2008-04-18 16:11:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon May 12 19:29:42 CDT 2008.