#pragma hdrstop无参数在多个文件中使用时做什么? [英] What does #pragma hdrstop without parameter do when used in multiple files?

查看:136
本文介绍了#pragma hdrstop无参数在多个文件中使用时做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在两个源(cpp)文件中放置 #pragma hdrstop (无文件名参数)的实际价值是什么? / p>

请注意,



编辑/注意:我问这个问题,因为此答案和它链接的文章似乎推荐。但是我不明白为每个编译单元都有一个单独的 pch文件有什么好处。

解决方案

p>原始问题的答案是,#pragma hdrstop在一个没有/ YC或/ Yu设置的文件的目的是它被忽略,所以你可以设置一个构建配置,没有预编译头和其他构建配置构建WITH预编译头文件,您不需要更改完全包含的代码或头文件。



更多详细...



MSDN上的注释说hdrstop pragma可以对预编译文件名以及保存编译状态的位置进行额外的控制。



简单来说,




  • 将#pragma hdrstop放在不使用/ Yc或/ Yu编译的源文件中不起作用。

  • 如果您有/ Yu

  • 如果为文件设置了/ Yc,那么hdrstop表示保存文件,然后hdrstop指定保存文件



诀窍是使用/ Yc和/ Yu没有可选的头文件名;只需检查使用或创建单选按钮,并将通过标题编辑框留空(或编辑项目文件...)。



有1个文件,可能称为PrecompiledHeader.cpp,其中包括要包括在预编译头中的头,并且在include文件列表的末尾有#pragma hdrstop。这个ONE文件是用/ Yc编译的。



然后你的所有其他cpp文件#pragma hdrstop之后的包含文件,在你的预编译头。这些文件都用/ Yu编译。



这会导致PrecompiledHeader.cpp构建你的(在这个例子中)单个pch文件和所有其他文件使用单个pch文件。



这样做的优点是,你的文件的NONE需要包含一个全局预编译头构建头文件 - 所以没有stdafx.h或其他。这意味着您可以设置一个构建没有预编译头的构建配置,其中所有#pragma hdrstop行都被忽略。



这是好的,因为它意味着你可以有一个单一的无precomp构建配置,让你迅速开发(你可以改变一个标题,世界重建)和其他正常配置,使用预编译头。


What is the practical value ("what does it do") of putting #pragma hdrstop (no filename parameter) in a couple of source (cpp) files?

Note that the MSDN docs are (once again) as clear as mud to me.

Edit/Note: I'm asking this, because this answer and the article it links to seem to recommend that. But I do not understand what benefit it has to have a separate pch file for each compilation unit.

解决方案

The answer to the original question is that the purpose of having #pragma hdrstop in a file with neither /Yc or /Yu set is that it's ignored and so you can set up a build configuration which builds without precompiled headers and other build configurations that build WITH precompiled headers and you don't need to change the code or the headers that are included at all to do so.

More detail...

The notes on MSDN say that "The hdrstop pragma gives you additional control over precompilation file names and over the location at which the compilation state is saved." which is true, but it's not especially obvious exactly how useful that can be...

In a nutshell.

  • Putting #pragma hdrstop in a source file that isn't compiled with /Yc or /Yu has no effect at all.
  • If you have /Yu set for the file then hdrstop tells the compiler to throw away everything before the line on which hdrstop appears and insert the precompiled header instead.
  • If /Yc is set for the file then hdrstop means save all of the compiled state for everything up to the line on which hdrstop appears as the precompiled header.

The trick is using /Yc and /Yu without the optional header file name; just check the 'use' or 'create' radio button and leave the 'through header' edit box blank (or edit the project file...).

So you have 1 file, possibly called PrecompiledHeader.cpp which includes the headers that you want to include in the precompiled header and which has #pragma hdrstop at the end of the list of include files. This ONE file is compiled with /Yc.

You then have all your other cpp files with #pragma hdrstop after the include files that are in your precompiled header. These files are all compiled with /Yu.

This results in PrecompiledHeader.cpp building your (in this example) single pch file and all of the other files using that single pch file.

The advantage in doing this is that NONE of your files need to include a 'global' precompiled header building header file - so no stdafx.h or whatever. This means that you can set up a build configuration which builds WITHOUT precompiled headers where all of the #pragma hdrstop lines are simply ignored.

This is "good" because it means that you can have a single 'no precomp' build configuration which lets you develop quickly (you can change a single header and NOT force the world to rebuild) and other "normal" configurations that DO use precompiled headers.

这篇关于#pragma hdrstop无参数在多个文件中使用时做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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