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.


|