我的C++应用程序(使用g ++编译)需要在Pentium-4(32位)及更高版本上运行.但是,它通常与Core2Duo或更好的处理器一起使用.
我目前正在使用:-march = pentium4 -mtune = pentium4.但有些阅读促使我认为-march = pentium4 -mtune = generic可能会更好.
任何人都可以对此有所了解吗?在这种情况下,march&mtune选项的最佳值是什么?
平台:RHEL 5.3(32位)上的GCC 4.1.2.
我需要区分(重载)两个函数——一个接受一个const char*参数,另一个接受至少两个参数——一个const char*后跟一个或多个参数。即基本上:
void f(const char *str);
void f(const char *format, ...)
Run Code Online (Sandbox Code Playgroud)
我想要第一个版本被调用,f("hello")第二个版本被调用f("hello %d", 10)。上述重载将不起作用,因为编译器发现f("hello")歧义。
所以我试过这个:
void f(const char *str);
template<typename T>
void f(const char *str, T tt, ...);
Run Code Online (Sandbox Code Playgroud)
这使得重载解析正常工作。但我最终遇到了另一个问题。第二个函数应该转发 printf 样式使用的参数。所以我有类似的东西:
template <typename T>
void f ( const char *format, T tt, ... )
{
(T)tt;
va_list varlist;
va_start(varlist, format);
vprintf(format, varlist);
va_end(varlist);
}
Run Code Online (Sandbox Code Playgroud)
现在第二个参数tt不再是变量参数列表的一部分,并且调用va_start()withformat 似乎不起作用。
有什么办法可以实现我想要的吗?