473,698 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing a printf statement from my program causes it to crash!?

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.

May 25 '06
14 6867
"Harman Dhaliwal" <ha*******@gmai l.com> writes:
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.


You probably have some undefined behavour elsewhere in the code.
You seldom need some debugger.
--
espen
May 25 '06 #11
Joe Smith wrote:
"Richard Heathfield"
ha*******@gmail .com said:
I am relatively new to C and am
approaching from a high level language (java) background


The cause of your C problem is an error in the way you are using
pointers.


Did the claim that printf managed to print a negative number of
characters figure into this diagnosis? joe


Look up the specification of printf. A negative return value
indicates error. This probably has nothing to do with the OPs
problem. He probably has some sort of undefined behaviour
somewhere, such as a buffer overrun or a bad pointer.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
May 26 '06 #12

"CBFalconer " <cb********@yah oo.com> wrote in message
news:44******** *******@yahoo.c om...
Joe Smith wrote:
"Richard Heathfield"
ha*******@gmail .com said:

I am relatively new to C and am
approaching from a high level language (java) background

The cause of your C problem is an error in the way you are using
pointers.
Did the claim that printf managed to print a negative number of
characters figure into this diagnosis? joe


Look up the specification of printf. A negative return value
indicates error. This probably has nothing to do with the OPs
problem. He probably has some sort of undefined behaviour
somewhere, such as a buffer overrun or a bad pointer.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>

/* begin reply */
/* paste */

"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... "Joe Smith" <gr**********@n etzero.net> writes:
"Richard Heathfield"
ha*******@gmail .com said:

I am relatively new to C and am
approaching from a high level language (java) background

The cause of your C problem is an error in the way you are using
pointers.


Did the claim that printf managed to print a negative number of
characters
figure into this diagnosis? joe


I don't recall any such claim.

printf() returns the number of characters printed, or a negative value
if an error occurs. Even if it were possible for it to print a
negative number of characters, there would be no way for it to
indicate that it had done so.


You are correct. The negative return was only premised. My claim is that
what is premised might have something to do with his output. joe

/* end paste */

My newsreader or server has definitely gone Indian on me. joe
May 26 '06 #13

Harman Dhaliwal wrote:
as soon as I remove the printf statements the program crashes with a
pointer error (usually tried reading x00000000 error).


Everyone is just guessing; let me guess too.

Either you've used an uninitialized automatic variable, or have
coded just "return;" where "return x;" was needed. The
printf() is irrelevant per se, but happens to change the value of
undefined register or memory.

Just a guess based on my own debugging experience. If
someone's making book I'll want at least 9-to-2 odds before
betting on this horse.

James

May 27 '06 #14

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 find this interesting. I had the same problem when I did something
like this:

int a =3;
int arr[a];

instead of using malloc()

I wonder what is special about printf() which caused it to cover up our
problem. Perhaps someone could shed some light on it, even though it
would be off-topic?

May 28 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
15011
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white spaces(if it more than once between two words). Is there any function we have in C which will find out the tabs and white spaces and returns the text in the follwong way -
8
2708
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
9
1374
by: Eric Lilja | last post by:
Hello, I have two code snippets I want you to look at. My program compiles without warnings (warning level set to max, gcc 3.4.3) with either snippet but the latter one causes a segfault at run-time. I know it contains non-standard constructs (using the MySql C api) but I wanted to know if it's printf() I'm misuing. Here are the snippets: /* m is of type MYSQL* */ unsigned int code = mysql_errno(m); const char *description =...
18
352
by: biras | last post by:
hi #include<stdio.h> void main( ) { char *p; p="yes"; printf(p);
102
4533
by: tom fredriksen | last post by:
Hi I was doing a simple test of the speed of a "maths" operation and when I tested it I found that removing the loop that initialises the data array for the operation caused the whole program to spend twice the time to complete. If the loop is included it takes about 7.48 seconds to complete, but when removed it takes about 11.48 seconds. Does anybody have a suggestion as to why this is so and whether I can trust the results of the...
11
3911
by: timmu | last post by:
Someone asked me a question about integer division and printf yesterday, I tell him he should do a casting to float/double before you do any interger division. But he doesn't think so, so I try to do some example to explain, However, after some trying, I confused when I try to do some integer constant division, I know I should do float division something like 3.0/6.0, but I'm still confused where the -0.124709 comes for the following...
19
9900
by: RedDevilDan | last post by:
I am working on a Memory Footprint Reduction project. I came across an idea to disable all printf statements so that less memory is required. In addition, when there is no single printf statement, the printf library will not be linked, so it further reduces the executable size. Is there an easy way to disable printf in a large project? In my project, we have thousands of C & C++ files. They don't have a common included common header. ...
18
2848
by: sam_cit | last post by:
Hi Everyone, int main() { printf("not included stdio.h"); } Yes, i haven't included stdio.h and my compiler would generate a warning and would assume that it would return a int, my question is how does the linker manage to link the function invocation to the proper
29
11089
by: candy_init | last post by:
Hi all, I just came across the following program: #include <stdio.h> int main() { float a = 12.5; printf("%d\n", a); printf("%d\n", *(int *)&a); return 0;
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.