Re: declaration of variable in for loop



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
.



Relevant Pages

  • Re: Wheres the mistake???
    ... Implicit int ... always a good idea to specify the return type of all functions anyhow. ... As I hope you are aware, a prototype is a function ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)
  • Re: newbie: an invalid name was supplied
    ... debug1: An invalid name was supplied ... Configuration file does not specify default realm ...
    (comp.security.ssh)
  • Re: Passing an invalid date to INTEGER-OF-DATE
    ... > specify an invalid date for the argument? ... > The 1985 COBOL standard says that anything can happen ("the result of ... > I would be interested to know the results for various compilers. ... Our compiler goes nuts when an invalid field is passed to FUNCTION ...
    (comp.lang.cobol)
  • Re: Adding property to form
    ... I am unable to vfp8 tells me it is an ... R> invalid name, any suggestions? ... or specify no columns at all: ... Eric den Doop ...
    (microsoft.public.fox.programmer.exchange)
  • Re: How can I get just one row from selected column?
    ... your XHTML code will be invalid) ... function (if you use double-quotes around attribute values, then you do not have to specify the second parameter for this function, but if you use single-quotes - as in the example above - then you ...
    (comp.lang.php)