我试着在VisualStudio 2010上测试rdtsc。下面是我的代码:
#include <iostream>
#include <windows.h>
#include <intrin.h>
using namespace std;
uint64_t rdtsc()
{
return __rdtsc();
}
int main()
{
cout << rdtsc() << "\n";
cin.get();
return 0;
}但是我得到了错误:
------ Build started: Project: test_rdtsc, Configuration: Debug Win32 ------
main.cpp
c:\documents and settings\student\desktop\test_rdtsc\test_rdtsc\main.cpp(12): error C2146: syntax error : missing ';' before identifier 'rdtsc'
c:\documents and settings\student\desktop\test_rdtsc\test_rdtsc\main.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\student\desktop\test_rdtsc\test_rdtsc\main.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\student\desktop\test_rdtsc\test_rdtsc\main.cpp(14): warning C4244: 'return' : conversion from 'DWORD64' to 'int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========我该怎么办?我不想把uint64_t改成DWORD64。为什么VisualStudio不理解uint64_t
发布于 2013-08-24 19:20:45
你必须使用#include <stdint.h>。或者(更好的) #include <cstdint>。
Visual Studio开始将这些标题与2010版本一起发布。
发布于 2013-08-24 19:38:17
要使其正常工作,您必须包含cstdint:
#include <cstdint> // Or <stdint.h>cstdint是C样式头文件stdint.h的C++样式版本。那么在您的情况下使用第一个更好,即使这两个都在C++中工作。
据说here从2010年开始就将这些头文件与visual studio一起发布。
发布于 2013-08-24 19:19:57
显然,您没有在顶部包含stdint.h/cstdint。这将会起作用:
#include <iostream>
#include <windows.h>
#include <intrin.h>
#include <stdint.h>
using namespace std;
uint64_t rdtsc()
{
return __rdtsc();
}
int main()
{
cout << rdtsc() << "\n";
cin.get();
return 0;
}https://stackoverflow.com/questions/18417942
复制相似问题