Gcc Mingw 4.8.2是否支持'#pragma once';

Gcc Mingw 4.8.2是否支持'#pragma once';,gcc,mingw,Gcc,Mingw,我目前有以下几个问题 gcc --version gcc (x86_64-win32-seh-rev3, Built by MinGW-W64 project) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY

我目前有以下几个问题

gcc --version
gcc (x86_64-win32-seh-rev3, Built by MinGW-W64 project) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我的问题是Mingw是否支持
#pragma
关键字,是否支持
#pragma once
真正的问题是gcc(Mingw系统的编译器部分)是否支持
#pragma once

答案是肯定的。gcc使用的C预处理器实际上支持
#pragma
特性,这是单独记录的。Gnu CPP实现的
#pragma once
。根据系统配置的不同,您可以通过键入
info cpp
并搜索
#pragma一次,在系统上读取此信息


但是,我不建议只使用一次pragma。它不是由C标准指定的,因此不能移植到其他编译器。除非您可以保证您的代码永远不需要由不支持
#pragma once
的编译器编译,否则您可能最好使用传统的
#ifndef
方法,即。

中所述的“include guard”(包含保护),您可以很容易地通过尝试来回答这个问题。“是的”这两个问题都由GCC、Visual C++、CLAN/LLVM、IBM C++和英特尔C++支持。我不知道这里还有其他编译器不支持#pragma one。也许是PGI?据我所知,波特兰集团的PGI编译器一次也不支持
#pragma
。那是我所知道的唯一一个。