polymorphism - 64 bit - va_arg - advanced

This is a discussion on polymorphism - 64 bit - va_arg - advanced within the C Programming forums, part of the General Programming Boards category; Does any one see how to have a type in a va_arg that can accept int(32 bit) or pointers(64bit) in ...

  1. #1
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

    polymorphism - 64 bit - va_arg - advanced

    Does any one see how to have a type in a va_arg that can accept int(32 bit) or pointers(64bit) in a 64 bit environment.

    This page suggests that VC++ will support %I in the future. I was wondering if there is any way to do this portably.
    http://msdn.microsoft.com/library/en...iderations.asp

    For example:

    We have INT_PTR ip = va_arg(marker, void *);

    The problem is that when you have something like this:

    printf("%I", 100);

    The va_arg will read in 64bits(sizeof(void *)) when only 32 bits(sizeof(int)) have been supplied.

    I suspect this is impossible. Anyone have any ideas.

    PS. Is it possible that default type promotions will promote everything to 64bit despite sizeof(int) and sizeof(long) being 32 bit.

    Thanks.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,674
    Use %p or %n to handle pointers in a printf-style format specification.
    Since you specify a (void*) type to va_arg(), you should pass in a (void*) type:
    Code:
        printf("%p", (void*)10);
    gg

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Thanks for the reply, that's exactly what I have done. I assume MS will implement %I as a compiler extension.

    It's interesting that int and long have stayed at 32bits.

    On an unrelated note I found this site:
    http://www.opus1.com/vmsdoc/progtool...4/6180ptoc.htm

    It seems to be a nicely formatted html rewrite of the C standard from the programmer's perspective(rather than the implementor), although some of the information is specific to Compaq C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A few questions about 64 bit and Windows...
    By yaya in forum Tech Board
    Replies: 9
    Last Post: 08-28-2008, 08:49 AM
  2. binary numbers
    By watshamacalit in forum C Programming
    Replies: 4
    Last Post: 01-14-2003, 10:06 PM
  3. 64 bit variables
    By Yawgmoth in forum C Programming
    Replies: 11
    Last Post: 12-19-2002, 12:55 PM
  4. 64 bit
    By stormbringer in forum C Programming
    Replies: 2
    Last Post: 10-29-2002, 05:51 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21