Re: declaration of variable in for loop



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
.



Relevant Pages

  • Re: Linked list with void *
    ... > 1) When we use printf function to print something we use format ... > specifier for printing. ... But when it comes to void*, ...
    (comp.lang.c)
  • comparing files
    ... the columns represent the dimensions. ... can be specified for reals. ... Nonnegative width required in format string at ... stored in ES or some other real format specifier... ...
    (comp.lang.fortran)
  • Re: WRITE + new line
    ... compiler to format the output as it wishes. ... FORMAT statements if YOU want to specify the output format. ... Examine the ADVANCE= specifier of the WRITE statement. ... * Any use of tradenames does not constitute a NOAA endorsement. ...
    (comp.lang.fortran)
  • Re: queries about sprintf
    ... > different data type from the one specified in the format argument. ... Since sprintf is a variadic function, ... specifier); other pointer types need to be properly cast. ... requires a value of type int, ...
    (comp.std.c)
  • Re: String Format
    ... Standard numeric format strings are used to format common numeric ... integer called the precision specifier. ... The number is converted to a string of hexadecimal digits. ...
    (microsoft.public.dotnet.languages.csharp)