Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / August 2003

Tip: Looking for answers? Try searching our database.

Visual C++ .NET 2003 Optimiser BUG - small example included

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aaron Queenan - 13 Aug 2003 17:44 GMT
va_arg doesn't work correctly in functions which have been inlined.  Either
the compiler should reject functions using va_arg as candidates for
inlining, or the implementation of va_arg should be fixed to work correctly.

The example below has been tested at warning level 4 with the /Wall compiler
switch.  Warning 4711 has been left enabled so that you can see when the
function has been automatically inlined.

   // Vararg.cpp : Defines the entry point for the console application.
   //
   #pragma warning(disable : 4710)

   #pragma warning(push)
   #pragma warning(disable : 4217 4619 4668 4820)
   #include <iostream>
   #include <cstdarg>
   #pragma warning(pop)

   //#pragma auto_inline(off)
   int TestVararg(int intFirst, int /*intSecond*/)
   {
       va_list argList;
       va_start(argList, intFirst);
       int arrInt = va_arg(argList, int);
       va_end(argList);
       return arrInt;
   }

   int main()
   {
       std::cout << TestVararg(1, 123456789) << std::endl;
       return 0;
   }

   #pragma warning(disable : 4514)

The example works correctly in Debug mode (which never auto-inlines
functions), and in Release mode when #pragma auto_inline(off) is used, but
returns the wrong value when the function is inlined.  I have tested it in
Visual C++ .NET 2003, but not in VC++ .NET 2002 (MOD XP broke my
installation and won't uninstall or reinstall no matter what I do) or VC++ 6
because I don't have it installed.

Regards,
Aaron Queenan.
Doug Harrison [MVP] - 13 Aug 2003 19:22 GMT
>va_arg doesn't work correctly in functions which have been inlined.  Either
>the compiler should reject functions using va_arg as candidates for
[quoted text clipped - 38 lines]
>installation and won't uninstall or reinstall no matter what I do) or VC++ 6
>because I don't have it installed.

<cstdarg> is only for dealing with variadic functions. It should work fine
if you declare TestVararg as:

int TestVararg(int intFirst, ...)

P.S. A better group for VC.NET questions is:

microsoft.public.dotnet.languages.vc

Signature

Doug Harrison
Microsoft MVP - Visual C++

Aaron Queenan - 13 Aug 2003 19:52 GMT
> >va_arg doesn't work correctly in functions which have been inlined.  Either
> >the compiler should reject functions using va_arg as candidates for
[quoted text clipped - 43 lines]
>
>  int TestVararg(int intFirst, ...)

That works okay for this scenario, so I guess the auto-inlining just looks
for '...' in the argument list rather than being a bit more clever and
looking at the implementation of the function.

Unfortunately, the function in our application is overloaded with many
different argument counts so we can't use '...'.  :-(

Varargs was useful because it meant that we didn't have to implement every
version manually.  I've disabled inlining now, so hopefully that is the only
scenario that causes problems.

> P.S. A better group for VC.NET questions is:
>
> microsoft.public.dotnet.languages.vc

Thanks.  I was wondering why microsoft.public.vsnet.development didn't exist
and what the equivalent was.  :-)

Regards,
Aaron Queenan.
Doug Harrison [MVP] - 13 Aug 2003 20:52 GMT
>That works okay for this scenario, so I guess the auto-inlining just looks
>for '...' in the argument list rather than being a bit more clever and
[quoted text clipped - 6 lines]
>version manually.  I've disabled inlining now, so hopefully that is the only
>scenario that causes problems.

If at all possible, I'd fix the code. It's incorrect to use va_start on a
parameter which does not immediately precede the ellipsis. I know your
example was probably very much simplified, and I'm having a hard time
visualizing a more realistic application of this, so I can't make any
specific suggestions without seeing more code.

Signature

Doug Harrison
Microsoft MVP - Visual C++


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.