wu18946796976 发表于 2019-8-21 15:25:47

#pragma once在keil中怎么使用

#pragma once可以在keil中使用吗,为什么我用了以后系统提示警告
#pragma once in main file求解
是不可以用还是需要怎么设置

stm1024 发表于 2019-8-21 16:29:23

这个受到编译器特性影响,如果编译器(准确来说应该是预处理器)不支持,就没法使用。
实在不行还是老老实实的#ifndef吧。

TLLED 发表于 2019-8-21 17:33:14

keil 好像不支持#pragma once关键字

wu18946796976 发表于 2019-8-22 08:11:50

TLLED 发表于 2019-8-21 17:33
keil 好像不支持#pragma once关键字

多谢不支持那就没办法了

wu18946796976 发表于 2019-8-22 08:12:55

stm1024 发表于 2019-8-21 16:29
这个受到编译器特性影响,如果编译器(准确来说应该是预处理器)不支持,就没法使用。
实在不行还是老老实 ...

多谢不支持就没办法了 。。。。

Dandjinh 发表于 2019-8-22 08:47:24

换成V6编译器应该可以,V6是clang,用的是gcc那一套

wu18946796976 发表于 2019-8-22 09:41:01

Dandjinh 发表于 2019-8-22 08:47
换成V6编译器应该可以,V6是clang,用的是gcc那一套

good换成V6真可以啊赞一个用V6有没有其他问题先用一段时间看看

butterflyspring 发表于 2019-8-22 15:42:20

不过很多例程代码都没用到这个,所以按常规的写代码也有好处的:lol

stm1024 发表于 2019-8-23 11:12:03

wu18946796976 发表于 2019-8-22 08:12
多谢不支持就没办法了 。。。。

#pragma once

9.90 #pragma once
Enable the compiler to skip subsequent includes of that header file.
#pragma once is accepted for compatibility with other compilers, and enables you to use other forms of header guard coding. However, ARM recommends to use #ifndef and #define coding because this is more portable.
Example
The following example shows the placement of a #ifndef guard around the body of the file, with a #define of the guard variable after the #ifndef.
#ifndef FILE_H
#define FILE_H
#pragma once         // optional
... body of the header file ...
#endif
The #pragma once is marked as optional in this example. This is because the compiler recognizes the #ifndef header guard coding and skips subsequent includes even if #pragma once is absent.
需要翻译吗?哈哈

wu18946796976 发表于 2019-8-24 10:18:40

stm1024 发表于 2019-8-23 11:12
#pragma once

9.90 #pragma once


太小瞧我了   这点水平还是有的:D
这是语法功能啊这个我知道编译器现在不识别现在已经解决了换成V6的编译器就可以了
页: [1]
查看完整版本: #pragma once在keil中怎么使用