Re: Hellp with type promotion



manochavishal@xxxxxxxxx wrote:

int main(void)
{
char c = 'C';
test(c);

return 0;
}

void test(char c)
{
printf("Size of char is %d",sizeof(c));

}

1. This code is not legal. You don't have a declaration for test, and
the definition is different than the default declaration you would get
with a pre-C99 compiler. Also, printf() is a variadic function a
requires a prototype. The best way is to include <stdio.h>

2. Even if there were a legal implicit declaration or an old-style
declaration, that wouldn't matter. Except for variable-length arrays,
sizeof is performed at compile time. What the arguments get promoted to
at run-time have no bearing on what's printed there. It will be
sizeof(char), which is guaranteed to be 1, always.



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

  • Re: MFC dll and exe porting to 64-bit
    ... Why the obsolete 'char *' instead of the proper LPTSTR? ... We are no longer programming 16-bit windows in an 8-bit character world, ... string arguments should probably be LPCTSTR, that is, const parameters. ... declaration of the function itself, in context (meaning show the surrounding class ...
    (microsoft.public.vc.mfc)
  • Re: malloc warning gcc > 4.0
    ... > char* p; ... > warning: incompatible implicit declaration of built-in function 'malloc' ...
    (comp.lang.c.moderated)
  • Re: Banks and economy
    ... char cptr; ... I'm assuming that it's at file scope, because otherwise the array declaration wouldn't be allowed. ... In some cases, a tentative definition with no corresponding external definition ends up being treated as the actual definition, with an implicit initializer of 0. ...
    (comp.lang.c)
  • Re: Access one character in an array of characters
    ... enum Suit; ... Without seeing the exact declaration of ClubArray I cannot be certain, ... but you have probably declared it as a C-style string, ... confusion between a string and a vector of char. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Warning with K&R style function definition
    ... definition (which is also a declaration). ... void floo; ... int floo(int goo, char *shoo, const struct glue **moo) ...
    (comp.lang.c)