Re: declaration of variable in for loop
- From: Willem <willem@xxxxxxxx>
- Date: Thu, 31 Jan 2008 17:38:38 +0000 (UTC)
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 ?
) Also the '*' character in your format string
) specifies that the following formatting operation be of the minimum
) field width specified by the corresponding argument to '*'.
Only if the * is between the % and the d.
) This is implementation dependant. You cannot rely on the address of 'k'
) being the same across iterations. However the compiler is very likely
) to "optimise" in such cases and create and destroy 'k' only once for
) the entire duration of the loop. But you cannot rely on such behaviour.
The optimizer may even decide not to create or destroy k at all, when
it realises it's always equal to i, and at the printf call just insert
a seemingly valid value for the %p.
Have you looked at the assembly output for your loop ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
.
- Follow-Ups:
- Re: declaration of variable in for loop
- From: Walter Roberson
- Re: declaration of variable in for loop
- References:
- declaration of variable in for loop
- From: poornimamprabhu
- Re: declaration of variable in for loop
- From: santosh
- declaration of variable in for loop
- Prev by Date: Re: A solution for the allocation failures problem
- Next by Date: Re: declaration of variable in for loop
- Previous by thread: Re: declaration of variable in for loop
- Next by thread: Re: declaration of variable in for loop
- Index(es):
Relevant Pages
|