Re: Hellp with type promotion



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



Relevant Pages

  • Re: error
    ... foo.c:50: warning: string constant runs past end of line ... foo.c:7: warning: declaration of `n' shadows global declaration ... foo.c:29: warning: return type of `main' is not `int' ... char check(int n_, ...
    (comp.lang.c)
  • Re: malloc inside function (I know... I *did* search google first ;)
    ... malloc.c:2: warning: return type defaults to `int' malloc.c: In function `main': malloc.c:4: warning: implicit declaration of function `initialize_f' malloc.c:6: error: parse error before '/' token malloc.c: At top level: malloc.c:12: error: conflicting types for 'initialize_f' malloc.c:4: error: previous implicit declaration of 'initialize_f' was here malloc.c: In function `initialize_f': malloc.c:14: warning: implicit declaration of function `malloc' ... int main ... float * f; ...
    (comp.lang.c)
  • Re: regarding free
    ... char * process ... //code for copying the data to temp which are only in odd places. ... foo.c:4: warning: implicit declaration of function `malloc' ... foo.c:6: warning: implicit declaration of function `process' ...
    (comp.lang.c)
  • Re: gets() is dead
    ... a warning enabled on the various servers I have some control over, ... Unconditionally convert any call to getsto a warning message ... char *options; ... int mode; ...
    (comp.lang.c)
  • Re: Compile Time Error ... arghh
    ... foo.c:12: warning: function declaration isn't a prototype ... foo.c:13: warning: implicit declaration of function `malloc' ... int ccarray_destroy; ... char *dupstr; ...
    (comp.lang.c)