Path: Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 01 May 2024 03:36:07 +0000 From: steve Newsgroups: comp.lang.c Subject: Re: avoiding strdup() References: <87y1ayj6hs.fsf_-_@bsb.me.uk> <87r0gizzuo.fsf@nosuchdomain.example.com> <20240310101101.00001fd4@yahoo.com> <20240310100715.866@kylheku.com> <87v840z11t.fsf@fuzy.me> Date: Tue, 30 Apr 2024 23:36:02 -0400 Message-ID: <87ttji19wd.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:iWIQw3s0INyqGRde6/3tvJrpNVY= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 44 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-9Rhce4jlW9Ad21i72p353+J07YHP9Ych0nIQjHnbM0YRPXxZDdf50XbeM5LW5neseYqrdrFYiJG4gFf!3dcJfLZsbgAiZoO9T3B8Hvs5se/5UYl6ceHIAMlccxhR0g== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Bytes: 2756 i@fuzy.me writes: > Lawrence D'Oliveiro writes: > < > I was looking at the systemd source code the other day, and came across a < > lot of this sort of thing: < > < > _cleanup_free_ char *link = NULL; < > < > Now, what do you suppose “_cleanup_free_” does? > I usually use void * , probably a struct of some sort for marking garbage. > It's a dark magic of GCC to automatically free the memory when pointer > goes out of scope. Try alloca - for stack loading; there is a garbage collector for C . The Boehm-Demers-Weiser conservative can be used in place of malloc. with gcc you can stack allocate with nested functions, like in object pascal. `` A “nested function” is a function defined inside another function. Nested functions are supported as an extension in GNU C, but are not supported by GNU C++. The nested function's name is local to the block where it is defined. For example, here we define a nested function named ‘square’, and call it twice: foo (double a, double b) { double square (double z) { return z * z; } return square (a) + square (b); } from the gcc info manual. '' have fun; gcc is a greate compiler.