#### Archived

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

# varargs in .NET

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

## 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 on other sites
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 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 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 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 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]

1. 1
2. 2
frob
20
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632210
• Total Posts
3004797

×