Wierd Visual Studio问题 [英] Wierd Visual Studio Problem

查看:52
本文介绍了Wierd Visual Studio问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有以下代码,我使用C在Visual Studio 2008上运行和编译成功,但问题是程序试图运行第一次免费调用它只是挂在那里什么都不做:S。在GNU Linux中,程序运行正常但是windows显示了一个非常奇怪的行为。


这里是代码


动态创建一个2D数组

Hi,

I have the following code that I run and compile successfully on Visual Studio 2008 using C, but the problem is when the program tries to run the first free call it just hangs there and does nothing :S. In GNU Linux the program runs fine but windows shows a very strange behavior with this.

here is the code

Create a 2D array dynamically

展开 | 选择 | Wrap | 行号

推荐答案

嘿m8,


好​​吧似乎linux可能有更好的内存管理(并且更智能),但它有点不符合执行此类操作的标准。你的代码是正确的,绝对正确,但有一个例外,分配字符串所需的大小。


图片:

Hey m8,

Well as it seems maybe linux has a better memory management (and smarter) but it''s kinda off the standard to perform such actions. Your code is correct and absolutely right but with one exception, the size needed for allocation of the string.

Picture this:

展开 | 选择 | Wrap | 行号


实际上,您正在创建一个char *的一维数组。


C / C ++中的所有数组都是一维。


阅读: http ://bytes.com/topic/c/insights/77...rrays-revealed

注意最后的例子le。
Actually, you are creating a one-dimensional array of char*.

All arrays in C/C++ are one dimensional.

Read this: http://bytes.com/topic/c/insights/77...rrays-revealed.

Pay attention ot the last example.


从技术上讲,我同意,但在这种情况下,他创建了一个指向实际字符串的一维字符串指针数组。这就是为什么他在免费期间也遇到了问题,因为它没有找到何处结束解除分配并导致函数锁定;)
Technically speaking yea I agree, but in this case he created a one-dimensional array of string pointers that point to the actual string. That''s why he also had a problem during free because it didn''t find where to end deallocation and caused the function to lock ;)


这篇关于Wierd Visual Studio问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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