X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com Date: Wed, 20 Jul 2011 20:45:11 +0300 From: Eli Zaretskii Subject: Re: printf statement causes error message In-reply-to: X-012-Sender: halo1 AT inter DOT net DOT il To: djgpp AT delorie DOT com Message-id: <83mxg8vobc.fsf@gnu.org> References: Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > From: Mok-Kong Shen > Date: Wed, 20 Jul 2011 18:58:58 +0200 > Bytes: 1820 > > Could some expert kindly tell why the one printf statement in the > main program below causes the trouble? Because you try to `free' a pointer whose value is garbage? Here: > void test() > { int *hh; <<<<<< uninitialized pointer, value is garbage > printf("abc\n"); free(hh); printf("def\n"); > } > > int main() > { // If the following printf statement is commented out > // then no error message ("Exiting due to signal SIGSEGU") > > printf("calling test\n"); It has nothing to do with `printf' per se: simply, a call to `printf' allocates some memory internally, and then the garbage in hh is different, so it causes a crash.