VC ++会生成哪种类型的构造来生成局部变量? [英] Which sort of constructs makes VC++ generate local variables?

查看:78
本文介绍了VC ++会生成哪种类型的构造来生成局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是弄清楚哪种代码使VC ++编译器生成局部变量.

I am interested in figuring out which sort of code makes the VC++ compiler generate local variables.

背景是我一直在使用VC ++ 2010的代码分析器,并且在许多地方,代码分析器发现了CA1809类型的错误:避免使用过多的本地语言.就我而言,该函数使用68个局部变量,其中62个 由编译器生成. 文档不能提供有关使编译器生成局部变量的哪种构造的信息,并且大量的google搜索都未提供任何信息.快速而肮脏的修复方法是将功能分解为较小的功能,但我担心 可能会混淆我代码中的潜在问题.我在代码分析"论坛中提出了要求,他们将我引导到了这里.

The background is that I have been using the code analyzer for VC++ 2010, and in a number of places, the code analyzer has found errors of the type CA1809: Avoid excessive locals. In my case, the function in question uses 68 local variables, of which 62 are generated by the compiler. The documentation is not informative on which sort of constructs that make the compiler generate local variables, and numberous google searches have not turned up anything. A quick and dirty fix is to break up the function into smaller functions, but I am worried that it might obfuscate underlying issues in my code. I have asked in the Code Analysis forum and they directed me here.

那么,有谁知道使编译器生成局部变量的哪种构造?代码示例将不胜感激.

So, does anyone know which sort of constructs that make the compiler generate local variables? Code examples would be appreciated.

应该注意的是,产生错误的函数是单元测试,因此对我来说不是关键问题.我只是很好奇.

It should be noted that the function generating the error is a unit test, so it is not a critical issue for me. I'm just curious.

推荐答案

代码大小和数据大小的用法取决于编译器设置.您可以通过几种设置来创建优化的代码(大小/速度/..).如果您分析了带有调试信息的代码,我想您使用的局部变量将比 具有优化代码的发行版本.

The usage of code size and data size depends on the compiler settings. You have several settings to create optimized code (size / speed / ....). If you analyzed a code with debug information I'd guess you will have also more local variables in use than in a release build with optimized code.

对我来说,这还取决于您编码的功能.事实是,如果某些计算结果以后可以重用,通常有充分的理由使用局部变量来提高计算的执行速度.

For me it also depends on the function you have coded. It is fact that there are often good reasons for using local variables for increasing the execution speed for calculations if some results of the calculations may be reusable later.


这篇关于VC ++会生成哪种类型的构造来生成局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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