Re: main function address
From: pete (pfiland_at_mindspring.com)
Date: 04/07/04
- Next message: Prem Mallappa: "BooK "Obfsucated C and other mysteries""
- Previous message: Leor Zolman: "Re: help signed and unsigned in 64bits"
- In reply to: Lew Pitcher: "Re: main function address"
- Next in thread: Martin Dickopp: "Re: main function address"
- Reply: Martin Dickopp: "Re: main function address"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 07 Apr 2004 12:27:22 GMT
Lew Pitcher wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> pete wrote:
> | Martin Dickopp wrote:
> |
> |>Lew Pitcher <lpitcher@sympatico.ca> writes:
> |>
> |>
> |>>#include <stdio.h>
> |>>#include <stdlib.h>
> |>>
> |>>int main(void)
> |>>{
> |>> printf("main() at %p\n",(void *)&main);
> |>>
> |>> return EXIT_SUCCESS;
> |>>}
> |>
> |>Is the cast to `void *' valid?
> |
> |
> | No.
> |
> | In N869, it's one of the common extensions.
> |
> | J.5.7 Function pointer casts
> | [#2] A pointer to a function may be cast to a pointer to an
> | object or to void, allowing a function to be inspected or
> | modified (for example, by a debugger) (6.5.4).
> |
> | ... which makes it more obviously not part of standard C.
>
> In 9989-1999 (admittedly, just the draft C99 standard, and not the
> /actual standard itself), the printf() function documentation in
> 7.19.6.3 refers the reader to the fprintf() documentation for a
> description of it's input. The fprintf() documentation in 7.19.6.1 says
> of the %p format
>
> ~ p The argument shall be a pointer to void. The value of the pointer is
> ~ converted to a sequence of printing characters, in an
> ~ implementation-defined manner.
>
> So, to satisfy the %p format character, the argument to
> fprintf()/printf() /must/ be a "pointer to void". Since main is a
> "pointer to function returning int", and not a "pointer to void", I
> interpreted the documentation as requiring a cast to void pointer.
I interpret it as meaning that printing the address of a function
isn't something that you are guaranteed to be able to do.
-- pete
- Next message: Prem Mallappa: "BooK "Obfsucated C and other mysteries""
- Previous message: Leor Zolman: "Re: help signed and unsigned in 64bits"
- In reply to: Lew Pitcher: "Re: main function address"
- Next in thread: Martin Dickopp: "Re: main function address"
- Reply: Martin Dickopp: "Re: main function address"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]