#endif之后的令牌合法吗? [英] Are tokens after #endif legal?

查看:103
本文介绍了#endif之后的令牌合法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在执行以下操作,并且编译器(MSVC2008和2010)没有对此抱怨,但是我不确定这是否是个坏主意:

I currently do the following and the compiler (MSVC2008 / as well as 2010) doesn't complain about it but I'm not sure if it's a bad idea or not:

#ifndef FOO_H_
#define FOO_H_

// note, FOO_H_ is not a comment:
#endif FOO_H_

我以前总是将其写为#endif // FOO_H_,但今天我发现自己没有这样做,并认为这很奇怪,因为显然我已经有一段时间没有使用注释方法了.

I used to always write it as #endif // FOO_H_ but I caught myself not doing that today and thought it was strange because apparently I've not done the comment method for a while.

这种不好的做法是我应该遍历所有标头并修复(这是一个跨平台的应用程序)还是可以保留原样?

Is this bad practice that I should go back through all of my headers and fix (it's a cross-platform application) or is it okay to leave it the way it is?

推荐答案

严格来说(根据标准中的语法),在#endif指令后的同一行中不允许使用令牌(注释被删除,因为它们被删除了,所以可以)在比翻译指令更早的翻译阶段-第3阶段对第4阶段.

Strictly speaking (according to the grammar in the standard) no tokens are allowed following the #endif directive on the same line (comments are OK since they get removed at an earlier phase of translation than the preprocessing directives - phase 3 vs. 4).

但是,MSVC似乎允许它-我不会寻求解决这些问题的方法(因为它们不会引起问题),但是在修改带有他们.

However, MSVC seems to allow it - I wouldn't go on a quest to fix these (since they aren't causing a problem), but would probably make a mental note to fix them as you modify the headers that have them.

当然,如果其他受支持的编译器发出有关它们的诊断信息,则可能更需要修复它们.

Of course, if your other supported compilers issue diagnostics about them it's probably more urgent to fix them.

这篇关于#endif之后的令牌合法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆