Deutsch English Français Italiano |
<87le2p5wd9.fsf@fatphil.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!feed.opticnetworks.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Phil Carmody <pc+usenet@asdf.org> Newsgroups: comp.lang.c Subject: Re: realloc() - frequency, conditions, or experiences about relocation? Date: Fri, 28 Jun 2024 11:01:38 +0300 Organization: A noiseless patient Spider Lines: 22 Message-ID: <87le2p5wd9.fsf@fatphil.org> References: <v4ojs8$gvji$1@dont-email.me> <v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org> <v52270$2nli8$1@dont-email.me> <v54jac$3a4p2$1@raubtier-asyl.eternal-september.org> <v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com> <v5dq2e$1eh23$11@dont-email.me> <87frt1tk0z.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Fri, 28 Jun 2024 10:17:26 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d4dc9bc4add6a62e4024cbb3babf20e6"; logging-data="3433464"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KlF1aTXDK9kT+yeq3jSem" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cancel-Lock: sha1:GTLycxsm0CzzYxgXfvGJO5URXZ0= sha1:91XU2IKmSrfu+62Z3c4eXmQzyaw= Bytes: 2052 Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: > Suppose you do something like: > > some_type *p = malloc(BIG_VALUE); > // ... > p = realloc(p, SMALL_VALUE); > > ... If realloc() succeeds and *does* relocate the object, p > still points to memory that has now been deallocated, and you don't have > a pointer to the newly allocated memory. Surely some mistake? However, such self-assignments are bad for the reasons you state later; verify, then update. Phil -- We are no longer hunters and nomads. No longer awed and frightened, as we have gained some understanding of the world in which we live. As such, we can cast aside childish remnants from the dawn of our civilization. -- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/