| www.delorie.com/archives/browse.cgi | search |
| 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 <eliz AT gnu DOT org> |
| Subject: | Re: printf statement causes error message |
| In-reply-to: | <j071gc$s6g$1@news.albasani.net> |
| X-012-Sender: | halo1 AT inter DOT net DOT il |
| To: | djgpp AT delorie DOT com |
| Message-id: | <83mxg8vobc.fsf@gnu.org> |
| References: | <j071gc$s6g$1 AT news DOT albasani DOT net> |
| 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 |
> From: Mok-Kong Shen <mok-kong DOT shen AT t-online DOT de>
> 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.
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |