Re: Hellp with type promotion



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



Relevant Pages