使用'...'参数调用函数的问题 [英] problem with calling function with '...' argument

查看:91
本文介绍了使用'...'参数调用函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有库(静态)testlib.cpp:

#include< stdarg.h>

void xxx(...)

{

char buf [100];

va_list args;

va_start(args,buf);

va_end(args);

}


和简单程序apptest.cpp:


#include" testlib.h"

int main()

{

char ala [100];

char ola [ 100];

xxx(ala,ola);

返回0;

}


没有编译错误,但链接器报告错误:未解析

外部符号void __cdecl xxx(...)" ;.

你有什么想法吗?如何解决这个问题。有趣的是,如果我将
函数xxx(...)放到apptest.cpp文件中 - 没有问题。

I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

#include "testlib.h"
int main()
{
char ala[100];
char ola[100];
xxx(ala, ola);
return 0;
}

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It''s intersting that if I
put function xxx(...) to apptest.cpp file - there is no problem.

推荐答案

j23写道:
我有库(静态)testlib.cpp:
#include< stdarg.h>
void xxx(...)
{char buf [100];
va_list args;
va_start(args,buf);
va_end(args);
}

和简单的程序apptest.cpp:



没有编译错误,但链接器报告错误:unresolved
外部符号" void __cdecl xxx(...)"
您知道如何解决此问题。如果我将函数xxx(...)放到apptest.cpp文件中,那就没问题了。
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

[...]

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It''s intersting that if I
put function xxx(...) to apptest.cpp file - there is no problem.




好​​吧,有你在项目中包含了testlib.lib?函数

xxx是否在库中导出?


另外,你对va_start(args,buf)绝对肯定吗?它对我来说看起来不够标准(buf应该是xxx的参数)。



Well, have you included testlib.lib in your project? Is the function
xxx exported in the library?

Another thing, are you absolutely sure about va_start(args, buf)? It
doesn''t look standard enough to me (buf should be a parameter of xxx).


你的内容是什么testlib.h看起来像?


-------------------------------- ---------

" j23" <无线************ @ supra.com.pl>在消息中写道

news:bm ********** @ atlantis.news.tpi.pl ...
what does your testlib.h look like?

-----------------------------------------
"j23" <wi************@supra.com.pl> wrote in message
news:bm**********@atlantis.news.tpi.pl...
我有库(静态)testlib .cpp:
#include< stdarg.h>
void xxx(...)
{char buf [100];
va_list args;
va_start(args,buf);
va_end(args);
}
和简单的程序apptest.cpp:

#include" testlib.h"
int main()
char ala [100];
char ola [100];
xxx(ala,ola);
返回0;
}
没有编译错误,但链接器报告错误:未解析
外部符号void __cdecl xxx(...)" 。
你知道如何解决这个问题吗?有趣的是,如果
我将函数xxx(...)放到apptest.cpp文件中 - 没有问题。
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

#include "testlib.h"
int main()
{
char ala[100];
char ola[100];
xxx(ala, ola);
return 0;
}

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It''s intersting that if I put function xxx(...) to apptest.cpp file - there is no problem.


j23写道:
我有库(静态)testlib.cpp:
#include< stdarg.h>
void xxx(...)
{
char buf [100];
va_list args;
va_start(args,buf);
va_end(args);
}
<简单的程序apptest.cpp:

#include" testlib.h"
int main()
{
char ala [100];
char ola [100];
xxx(ala,ola);
返回0;
}
没有编译错误,但链接器报告错误:未解析
外部符号void __cdecl xxx(...)"。
您是否知道如何解决此问题。如果我将函数xxx(...)放到apptest.cpp文件中,那就没有问题了。
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

#include "testlib.h"
int main()
{
char ala[100];
char ola[100];
xxx(ala, ola);
return 0;
}

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It''s intersting
that if I put function xxx(...) to apptest.cpp file - there is no
problem.




发布时,此代码是非法的 - 任何可能发生的事情,包括在运行时以任何方式失败

链接或行为不端。在

参数列表中使用省略号时,省略号必须在最后,并且必须在非参考类型的命名

参数之前。


编译器接受上述内容是编译器中的错误 - 根据C和C ++标准,它是严格违法的。 (这真的是你编译的,或者是上面缺少的东西吗?)


-cd



As posted, this code is illegal - anything could happen, including failing
to link, or misbehaving in any way at runtime. When using an elipsis in a
parameter list, the elipsis must come last, and must be preceeded by a named
parameter of non-reference type.

That the compiler accepts the above is an error in the compiler - it''s
strictly illegal according to the C and C++ standards. (Is it really what
you compiled, or is something missing from the above?)

-cd

这篇关于使用'...'参数调用函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆