从我的程序中删除printf语句会导致它崩溃!? [英] removing a printf statement from my program causes it to crash!?

查看:180
本文介绍了从我的程序中删除printf语句会导致它崩溃!?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编写一个数据库的内存表示形式,并且希望在实现时的尾端是

。但令人烦恼的一点是

,我的程序运行正常,我的所有诊断printf语句,但是当我删除printf语句时,程序崩溃了 >
指针错误(通常尝试读取x00000000错误)。


我已尝试过刷新缓冲区,跟踪完成

例程等等...任何人都可以向我提出一些建议吗?我可以试试吗?有没有人有类似的错误?

printf会导致删除它以阻止程序执行吗?

printf是否清空溢出的缓冲区?请原谅我的

感叹,但是我已经对这个问题感到震惊了近两天。

提前感谢您的回复。

解决方案



嗨哈曼,


我不是世界''最好的专家,但根据我的经验,每当你有这样的异常时,它表明动态分配的内存

是腐败的。仔细观察,确保所有需要分配的东西都是在使用之前分配的,并且一旦任何东西都是免费的,那么它就是b $ b永远不会被使用。再次。


Harman Dhaliwal写道:


我正在编写一个数据库的内存表示,我在
希望实施的尾端。但令人烦恼的一点是,我的程序在我的所有诊断printf语句中运行正常,但是一旦我删除了printf语句,程序崩溃就会出现
指针错误(通常尝试读取x00000000)错误)。

我已经尝试了一切,从刷新缓冲区,跟踪完成了例行程序等等......任何人都可以向我提出一些我可能会尝试的建议吗?有没有人有类似的错误?
printf会导致删除它以阻止程序执行吗?
printf是否清空溢出的缓冲区?请原谅我的哀叹,但我已经对这个问题感到震惊了近两天。
提前感谢您的回复。






" Snis Pilbor" < SN ******** @ yahoo.com>在消息中写道

嗨哈曼,
我不是世界上最好的专家,但根据我的经验,每当你有这样的异常时,它表明动态分配记忆
是腐败的。仔细观察以确保所有需要分配的东西在使用前分配,并且一旦任何东西都是免费的,它就永远不会被使用。再一次。

Harman Dhaliwal写道:


我正在编写一个数据库的内存表示,并且在尾端,希望如此实施。但令人烦恼的一点是,我的程序在我的所有诊断printf语句中运行正常,但是一旦我删除了printf语句,程序崩溃就会出现
指针错误(通常尝试读取x00000000)错误)。

我已经尝试了一切,从刷新缓冲区,跟踪完成了例行程序等等......任何人都可以向我提出一些我可能会尝试的建议吗?有没有人有类似的错误?
printf会导致删除它以阻止程序执行吗?
printf是否清空溢出的缓冲区?请原谅我的哀叹,但是我已经对这个问题感到震惊了近两天。
提前感谢您的回复。



Pilbor先生,请不要发帖。你(OP)是否一直关注printf上的

返回值? joe


Harman Dhaliwal schrieb:


我正在编写一个数据库的内存表示形式,我在
希望实施的尾端。但令人烦恼的一点是,我的程序在我的所有诊断printf语句中运行正常,但是一旦我删除了printf语句,程序崩溃就会出现
指针错误(通常尝试读取x00000000)错误)。

我已经尝试了一切,从刷新缓冲区,跟踪完成了例行程序等等......任何人都可以向我提出一些我可能会尝试的建议吗?有没有人有类似的错误?
printf会导致删除它以阻止程序执行吗?
printf是否清空溢出的缓冲区?请原谅我的哀叹,但是我已经打了好近2天了。
提前感谢您的回复。




这是未定义行为的一个缺点 - 它甚至可能看起来像是
工作,直到你删除对printf()的这个调用。所以你真正的错误

发生在printf()调用之前的某个地方,而你的程序是执行的



-

Marc Thrun
http://www.tekwarrior.de/


Hi,
I am programming an in memory representation of a database and am at
the tail end, hopefully, of implementation. But the vexing point is
that my program runs fine with all my diagnostic printf statements, but
as soon as I remove the printf statements the program crashes with a
pointer error (usually tried reading x00000000 error).

I have tried everything from flushing the buffer, tracking done the
routine, etc... can anyone offer me some suggestions to something I
might try? Has anyone had a similiar error? What is going on with
printf that would cause the removal of it to prvent program execution?
Does printf empty a buffer that is overflowing? Please excuse my
lamentations but I''ve hit my head against this for almost 2 days.
Thank you in advance for any response.

解决方案


Hi Harman,

I''m not the world''s best expert, but in my experience whenever you
have anomalies like this it suggests that dynamically allocated memory
is corrupt. Look closely to make sure everything that needs to be
allocated is allocated before use and that once anything is free''d, it
is never "used" again.

Harman Dhaliwal wrote:

Hi,
I am programming an in memory representation of a database and am at
the tail end, hopefully, of implementation. But the vexing point is
that my program runs fine with all my diagnostic printf statements, but
as soon as I remove the printf statements the program crashes with a
pointer error (usually tried reading x00000000 error).

I have tried everything from flushing the buffer, tracking done the
routine, etc... can anyone offer me some suggestions to something I
might try? Has anyone had a similiar error? What is going on with
printf that would cause the removal of it to prvent program execution?
Does printf empty a buffer that is overflowing? Please excuse my
lamentations but I''ve hit my head against this for almost 2 days.
Thank you in advance for any response.





"Snis Pilbor" <sn********@yahoo.com> wrote in message

Hi Harman, I''m not the world''s best expert, but in my experience whenever you
have anomalies like this it suggests that dynamically allocated memory
is corrupt. Look closely to make sure everything that needs to be
allocated is allocated before use and that once anything is free''d, it
is never "used" again.

Harman Dhaliwal wrote:

Hi,
I am programming an in memory representation of a database and am at
the tail end, hopefully, of implementation. But the vexing point is
that my program runs fine with all my diagnostic printf statements, but
as soon as I remove the printf statements the program crashes with a
pointer error (usually tried reading x00000000 error).

I have tried everything from flushing the buffer, tracking done the
routine, etc... can anyone offer me some suggestions to something I
might try? Has anyone had a similiar error? What is going on with
printf that would cause the removal of it to prvent program execution?
Does printf empty a buffer that is overflowing? Please excuse my
lamentations but I''ve hit my head against this for almost 2 days.
Thank you in advance for any response.



Mr. Pilbor, please don''t top post. Have you (OP) been keeping an eye of the
return value on printf? joe


Harman Dhaliwal schrieb:

Hi,
I am programming an in memory representation of a database and am at
the tail end, hopefully, of implementation. But the vexing point is
that my program runs fine with all my diagnostic printf statements, but
as soon as I remove the printf statements the program crashes with a
pointer error (usually tried reading x00000000 error).

I have tried everything from flushing the buffer, tracking done the
routine, etc... can anyone offer me some suggestions to something I
might try? Has anyone had a similiar error? What is going on with
printf that would cause the removal of it to prvent program execution?
Does printf empty a buffer that is overflowing? Please excuse my
lamentations but I''ve hit my head against this for almost 2 days.
Thank you in advance for any response.



This is one downside of undefined behaviour - it might even seem to
work, until you remove this call to printf(). So your real mistake
happened somewhere before the printf() was called while your program was
executing.

--
Marc Thrun
http://www.tekwarrior.de/


这篇关于从我的程序中删除printf语句会导致它崩溃!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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