Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

HappyDude

varargs in .NET

This topic is 5330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When Managed Extensions are in use, the compiler tells me I can''t use varargs: (warning C4793: native code generated for function ''Log::Error'': ''varargs not supported'') So, is there some new .NET equivalent?

Share this post


Link to post
Share on other sites
Advertisement
I dunno, I just tried it and declaring a function:

void Test(int,...);

worked perfectly well for me. It didn''t complain at all.

Share this post


Link to post
Share on other sites
I read your post, then set out to prove you wrong by writing a simple program proving my point. Of course, the program then went off and compiled, proving yours... goes to show, I should make sure I know exactly where the problem is before I ask about it...

That, however, doesn''t solve the problem . Reexamining code is currently in progress...

Share this post


Link to post
Share on other sites
Oddly enough, I''ve found more ways to do it now that work than ways that don''t now that I''ve actually tried rearranging the code, so the problem doesn''t really matter anymore, I can get around it easily enough.

But, it is still a point of interest... so, here''s some code that generates the error:

#include <cstdarg>
#include <cstdio>
#include <string>
using namespace std;

class Useless
{
public:
void Bleh(int nLine,char *sFile,string sProps);
void Blah(char *sErr, ...);

};

void Useless::Bleh(int nLine, char *sFile, string sProps)
{
}

void Useless::Blah(char *sErr, ...)
{
Bleh(0,"","Blah Blah");


va_list argList;
char sTemp[2048];
va_start(argList,sErr);
vsprintf(sTemp,sErr,argList);
va_end(argList);
}


If I use a char* instead of string, it stops complaining. If the members are put within the class definition instead of after it, that also stops it from complaining... so as far as I can tell, there''s no reason for it to complain about this paticular layout - but it does.

Share this post


Link to post
Share on other sites
Have you tried using something like params object[] obs in place of the ... , then just accessing those objects? It may help if you haven't.

EDIT:
NM, it's a C# keyword, there may be a managed c++ equivilant.



[edited by - cavemanbob on April 11, 2004 4:33:18 AM]

Share this post


Link to post
Share on other sites
The ParamArray attribute should be what you are looking for:
Example:

public __gc __interface IRenderable
{
void Render (IGE::IF_RenderDevice *ifRenderDev, IGE::HRENDERDEV renderDevHandle, [ParamArray]Object *args[]);
};


[edited by - VolkerG on April 11, 2004 5:08:54 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!