首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RDTSC on VisualStudio 2010 Express - C++不支持default-int

RDTSC on VisualStudio 2010 Express - C++不支持default-int
EN

Stack Overflow用户
提问于 2013-08-24 19:12:08
回答 3查看 12.2K关注 0票数 2

我试着在VisualStudio 2010上测试rdtsc。下面是我的代码:

代码语言:javascript
运行
复制
#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;
}

但是我得到了错误:

代码语言:javascript
运行
复制
------ 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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-08-24 19:20:45

你必须使用#include <stdint.h>。或者(更好的) #include <cstdint>

Visual Studio开始将这些标题与2010版本一起发布。

票数 3
EN

Stack Overflow用户

发布于 2013-08-24 19:38:17

要使其正常工作,您必须包含cstdint

代码语言:javascript
运行
复制
#include <cstdint> // Or <stdint.h>

cstdint是C样式头文件stdint.h的C++样式版本。那么在您的情况下使用第一个更好,即使这两个都在C++中工作。

据说here从2010年开始就将这些头文件与visual studio一起发布。

票数 2
EN

Stack Overflow用户

发布于 2013-08-24 19:19:57

显然,您没有在顶部包含stdint.h/cstdint。这将会起作用:

代码语言:javascript
运行
复制
#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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18417942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档