关闭Xcode中的变量的自动初始化 [英] Turn off automatic initialization of variables in Xcode

查看:135
本文介绍了关闭Xcode中的变量的自动初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在项目中,我正在开发Xcode,在启动/编译时,当我启动调试版本时,会自动将变量初始化为0。至少一切都是这样的。



我经常遇到这个问题,我没有将一个变量初始化为NULL - 这在Mac上工作正常,而当别人编译并启动项目(特别是在Windows机器上,因为它是一个多平台项目),他们得到一个 EXC_BAD_ACCESS ,因为 == NULL 是假的。



我很确定存在一个设置来关闭此行为,或者只是巧合,分配的内存是在我的机器上总是新鲜的

解决方案

可能只是巧合。



<关于每个现代的多用户操作系统,当操作系统为该进程提供新的内存时,它将擦除所有旧内容,以免从一个进程泄漏给另一个进程。所以当你第一次访问一些内存时,它就像被设置为0一样分开。



在某些情况下,使用调试版本更可能发生这种情况,因为优化通常包括降低堆栈占用空间,因此在早些时候重用某些内存。


In the project I'm working on Xcode automatically initializes variables to 0 on startup/ at compile time, when I start the debug build. At least everything looks like it.

I'm often running into the problem, that I haven't initialized a variable to NULL - which works fine on my Mac - and when someone else compiles and starts the project (especially on Windows machines, as it's a multiplatform project), they get a EXC_BAD_ACCESS, because == NULL is false.

I'm pretty sure there exists a setting to turn this behavior off, or is it just coincidental, that the allocated memory is always fresh on my machine?

解决方案

It is likely just coincidental.

On about every modern multi user OS, when the OS gives new memory to the process, it erases all old contents, to not have information leak from one process to the other. So when you access some memory the first time, it apepars as if it is set to 0.

This will happen in certain situations more likely when using debug builds, since optimization often includes lowering the stack footprint, thus is reusing certain memory much earlier.

这篇关于关闭Xcode中的变量的自动初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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