The usage of %p in C

Discussion in 'C Programming' started by Tak, Sep 25, 2007.

  1. How could that be a problem, even on a DS9K ?
    Charlie Gordon, Sep 26, 2007
    1. Advertisements

  2. Touche.
    Keith Thompson, Sep 26, 2007
    1. Advertisements

  3. The standard requires signed int and unsigned int to have the same
    size and alignment, and for values representable in both to have the
    same representation. But I don't think the standard requires the same
    parameter passing method for both.
    Keith Thompson, Sep 26, 2007
  4. Tak

    Martin Wells Guest


    Here's a case of where you can add NO overhead to your program and at
    the same time maintain its portability... YET you still strive to
    deportify your programs as best you can. You should start writing
    4294967295 instead of UINT_MAX, that'll further your cause even

    It's strange to see how someone could be so hellbent on causing
    inconvenience for themselves.

    Martin Wells, Sep 26, 2007
  5. Tak

    Old Wolf Guest

    Because the standard explicitly says that the argument
    corresponding to %x must be of type 'unsigned int'. The
    DS9K compiler could note that you pass a signed int,
    and replace the code with a call to nasal_demon().
    Old Wolf, Sep 26, 2007
  6. Tak

    Jack Klein Guest

    Jack Klein, Sep 27, 2007
  7. Tak

    Richard Bos Guest

    That is, effectively, not possible. (To be precise, if it is possible,
    it must be invisible to any conforming program, for the reason you
    mention above amongst others.) However, it has nothing whatsoever to do
    with pointers passed to variadic functions, so I fail to see why you
    appended that question to this thread.

    Richard Bos, Sep 27, 2007
  8. Even for varadic functions ?
    Charlie Gordon, Sep 28, 2007
  9. The standard requires this program to work:

    #include <stdio.h>
    #include <stdarg.h>

    void f(int a, ...) {
    va_list ap;
    va_start(ap, a);
    printf("%d %d\n", a, va_arg(ap, int));

    int main(void) {
    unsigned x = 1;
    f(x, x);
    return 0;

    The implementation must ensure an int value 1 is read even though an
    unsigned int value 1 is passed. However, so long as va_arg can find the
    right value in either case, the standard allows an int and an unsigned
    int to be passed differently (possibly by passing argument type
    information along with argument values). And there's nothing requiring
    the same va_arg handling from the *printf functions.
    =?iso-2022-kr?q?Harald_van_D=0E=29=26=0Fk?=, Sep 28, 2007
  10. Whoops you're right. C99 requires corresponding signed and
    unsigned to work properly for values that are representable in both
    (it also requires void* and pointers to character types to be

    As Harald points out, printf isn't required to use va_arg. But the
    DS9K is probably the only implementation where the above would fail
    (and it took a fair amount of work to cause that case to fail without
    breaking conformance).
    Keith Thompson, Sep 28, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.