Re: Hellp with type promotion
- From: "Default User" <defaultuserbr@xxxxxxxxx>
- Date: 28 Feb 2006 18:28:59 GMT
manochavishal@xxxxxxxxx wrote:
Hi,
it does promote to int type.
If we dont explicitly declare the function prototype, the function
argument character is promoted to int.
void test();
int main(void)
{
int n;
char c = 'C';
test(c);
printf("\nsize in main %d",sizeof(c));
return 0;
}
void test(c)
{
printf("size in func %d",sizeof(c));
}
This prints:
size in func 4
size in main 1
So if we dont tell compiler explicitly in the prototype the type of
arguments they are promoted.
Has nothing to do with promotion. You didn't give c a type in the
definition of test(). Therefore the implementation provided one for
you. The equivalent definition was:
void test(c)
int c;
{
}
So you got sizeof(int).
Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
.
- References:
- Hellp with type promotion
- From: manochavishal@xxxxxxxxx
- Re: Hellp with type promotion
- From: Ravi Uday
- Re: Hellp with type promotion
- From: manochavishal@xxxxxxxxx
- Hellp with type promotion
- Prev by Date: Re: Random Number Generators....
- Next by Date: a question of style
- Previous by thread: Re: Hellp with type promotion
- Next by thread: Re: Hellp with type promotion
- Index(es):
Relevant Pages
|