Re: declaration of variable in for loop
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 18:36:50 +0000
Walter Roberson wrote, On 31/01/08 17:45:
In article <slrnfq41su.1kq4.willem@xxxxxxxxxxxxxx>,
Willem <willem@xxxxxxxx> wrote:
santosh wrote:
) You probably want:
) printf("%d\t%p = %d\n", i, (void *)&k, k);
) The 'p' format specifier expects a void * value and the type of the
) value yielded by the address-of operator is "pointer to T" where T is
) the type of it's operand.
Aren't casts to and from (void *) automatic ?
No, not when passing a parameter to a function.
You mean not always when passed in all positions to a function. The following fragment is valid assuming stdio.h has been included.
void *fred = "fred is at %p\n";
printf(fred,fred);
This is valid because the prototype for printf specifies that the first parameters is of type const char *.
The following, on the other hand, is invalid
char *derf = "derf is at %p\n";
printf(derf,derf);
This is invalid because the prototype for printf does not specify the type of the second (or subsequent) parameter, so the rules of C specify that no conversion takes place. Change the %p to a %s and it becomes valid.
--
Flash Gordon
.
- References:
- declaration of variable in for loop
- From: poornimamprabhu
- Re: declaration of variable in for loop
- From: santosh
- Re: declaration of variable in for loop
- From: Willem
- Re: declaration of variable in for loop
- From: Walter Roberson
- declaration of variable in for loop
- Prev by Date: Re: Quick check on signed promotion of bytes
- Next by Date: Re: Question on accessing structure
- Previous by thread: Re: declaration of variable in for loop
- Next by thread: Re: declaration of variable in for loop
- Index(es):
Relevant Pages
|