Re: Hellp with type promotion
- From: Martin Ambuhl <mambuhl@xxxxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 16:51:50 GMT
manochavishal@xxxxxxxxx wrote:
HI,
I read that every char in expression is promoted to int.
So as function arguments are expressions so type promotion should take
place for arguments passed to function.
so
*****
int main(void)
{
char c = 'C';
test(c);
return 0;
}
void test(char c)
{
printf("Size of char is %d",sizeof(c));
}
*******
should print -Size of char is 4 - as the char c is promoted to type
int.
But it prints 1
Why??
The real question is why you either
1) have your diagnostics turned off or
2) are ignoring them.
These are the diagnostics gcc produces for your code:
a.c: In function 'main':
a.c:4: warning: implicit declaration of function 'test'
a.c: At top level:
a.c:10: warning: conflicting types for 'test'
a.c:4: warning: previous implicit declaration of 'test' was here
a.c: In function 'test':
a.c:11: warning: implicit declaration of function 'printf'
a.c:11: warning: incompatible implicit declaration of built-in function 'printf'
a.c:11: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
.
- References:
- Hellp with type promotion
- From: manochavishal@xxxxxxxxx
- Hellp with type promotion
- Prev by Date: Re: need help getting the results of the system function into a variable
- Next by Date: Re: need help getting the results of the system function into a variable
- Previous by thread: Re: Hellp with type promotion
- Next by thread: Re: Hellp with type promotion
- Index(es):
Relevant Pages
|