编译器抱怨volatile关键字

时间:2018-11-16 21:13:57

标签: c++ c compiler-errors

我正尝试从this问题中编译以下代码,但编译失败:错误C2059:语法错误:'volatile'

@SpringBootApplication
@ConditionalOnProperty(value = "scheduling.enable")
@EnableScheduling
@EnableCaching
public class AcmeServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(AcmeServiceApplication.class, args);
    }
}

我正在使用x godbolt上没有任何标志的x64 msvc v19(WINE)编译器

1 个答案:

答案 0 :(得分:2)

asm volatile是GNU扩展。限定词为documented here

对于MSVC,请改用__rdtscp intrinsic


此外,请注意,您可以在所有主要的编译器中使用内在函数,例如:

#include <iostream>
#include <cstdint>

#ifdef _WIN32
#  include <intrin.h>
#else
#  include <x86intrin.h>
#endif

int main()
{
    uint64_t i;
    uint32_t ui;
    i = __rdtscp(&ui);
    std::cout
        << "Ticks: " << i << '\n'
        << "TSC_AUX: " << ui << '\n'
    ;
    return 0;
}