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. VS2005 - ellipsis in a macro

VS2005 - ellipsis in a macro

Scheduled Pinned Locked Moved C / C++ / MFC
csharpphpquestion
4 Posts 2 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.
  • C Offline
    C Offline
    Chintoo723
    wrote on last edited by
    #1

    VS6 and VS2003 do not support varargs in a C macro. The link http://sourceforge.net/mailarchive/forum.php?forum_id=40270&max_rows=25&style=nested&viewmonth=200503[^] hints that this is possible in VS2005. I dont have VS2005 installed, can someone who has VS2005 quickly check if the following compiles? #define myprint(fmt, args_...) _snprintf(str, fmt, ##args_) char str[64]; myprintf("hello %s", "world"); thanks!

    M 1 Reply Last reply
    0
    • C Chintoo723

      VS6 and VS2003 do not support varargs in a C macro. The link http://sourceforge.net/mailarchive/forum.php?forum_id=40270&max_rows=25&style=nested&viewmonth=200503[^] hints that this is possible in VS2005. I dont have VS2005 installed, can someone who has VS2005 quickly check if the following compiles? #define myprint(fmt, args_...) _snprintf(str, fmt, ##args_) char str[64]; myprintf("hello %s", "world"); thanks!

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      VC8 does support it, you've got the syntax wrong though. It should be

      #define foo(fmt,...) _snprintf(str,fmt,__VA_ARGS__)

      More info[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      C 1 Reply Last reply
      0
      • M Michael Dunn

        VC8 does support it, you've got the syntax wrong though. It should be

        #define foo(fmt,...) _snprintf(str,fmt,__VA_ARGS__)

        More info[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        C Offline
        C Offline
        Chintoo723
        wrote on last edited by
        #3

        Cool, that is what I was looking for. Thanks. Now one more thing - is there any preprocessor variable that indicates what compiler is compiling the code? I want to write this macro seperately once for VC8 and once for VC6/VC7 so that the code can still be compiled with the older compiler, just in case someone wants to use the older compilers. thanks!

        M 1 Reply Last reply
        0
        • C Chintoo723

          Cool, that is what I was looking for. Thanks. Now one more thing - is there any preprocessor variable that indicates what compiler is compiling the code? I want to write this macro seperately once for VC8 and once for VC6/VC7 so that the code can still be compiled with the older compiler, just in case someone wants to use the older compilers. thanks!

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Chintoo723 wrote:

          is there any preprocessor variable that indicates what compiler is compiling the code?

          Yep, look up _MSC_VER in the help --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          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