Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how can i get all the arguments in the va_list

how can i get all the arguments in the va_list

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bbluey
    wrote on last edited by
    #1

    If i have a function myfunc(arg1,arg2,arg3), how can i include them, all, in a va_list variable? if i use va_start(list, arg1), i won't have arg1 in the list and I cannot change the singnature of the function myfunc. If I do something like: list = (va_list)&arg1 it works for types like int, unsigned int, even char*, but not float or double. If one of the args is float, it will store in list a 0 instead of the real value. please help :~

    B 1 Reply Last reply
    0
    • B bbluey

      If i have a function myfunc(arg1,arg2,arg3), how can i include them, all, in a va_list variable? if i use va_start(list, arg1), i won't have arg1 in the list and I cannot change the singnature of the function myfunc. If I do something like: list = (va_list)&arg1 it works for types like int, unsigned int, even char*, but not float or double. If one of the args is float, it will store in list a 0 instead of the real value. please help :~

      B Offline
      B Offline
      Bob Ciora
      wrote on last edited by
      #2

      You'd have to include a sizeof(arg1) to account for the stack space used by arg1 and include it. Something like this:

      char \* ArgPtr = (char \*)&arg1 - sizeof(arg1);
      if( ArgPtr == (char \*)&arg2 )
      {
          // Stack growing the other way...
          ArgPtr = (char \*)&arg1 + sizeof(arg1);
      }
      
      list = (va\_list)ArgPtr;
      

      That oughta take into account whatever way the stack grows. Bob Ciora

      B 1 Reply Last reply
      0
      • B Bob Ciora

        You'd have to include a sizeof(arg1) to account for the stack space used by arg1 and include it. Something like this:

        char \* ArgPtr = (char \*)&arg1 - sizeof(arg1);
        if( ArgPtr == (char \*)&arg2 )
        {
            // Stack growing the other way...
            ArgPtr = (char \*)&arg1 + sizeof(arg1);
        }
        
        list = (va\_list)ArgPtr;
        

        That oughta take into account whatever way the stack grows. Bob Ciora

        B Offline
        B Offline
        bbluey
        wrote on last edited by
        #3

        Indeed something like that works. Thank you Now something else troubles me regarding float. I make myself a list of the arguments. the list contains a char*, a float and something. I check them, they are ok. But when i'm tring to right them into a file using vfprintf(file,format,list), instead of my float value i always get a 0.00000 This is too much :-D

        R 1 Reply Last reply
        0
        • B bbluey

          Indeed something like that works. Thank you Now something else troubles me regarding float. I make myself a list of the arguments. the list contains a char*, a float and something. I check them, they are ok. But when i'm tring to right them into a file using vfprintf(file,format,list), instead of my float value i always get a 0.00000 This is too much :-D

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #4

          You should always use the va_ family of functions to do this. Anyway, floats are always pushed as doubles in var arg functions. You can check some assembly listings to verify this.

          B 1 Reply Last reply
          0
          • R Rick York

            You should always use the va_ family of functions to do this. Anyway, floats are always pushed as doubles in var arg functions. You can check some assembly listings to verify this.

            B Offline
            B Offline
            bbluey
            wrote on last edited by
            #5

            Thank you for your help. Indeed when i use va_arg to extract my float the result is corect, so I'll just use a printf :-D Thanks again

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups