Sujet : Re: avoiding strdup()
De : sgonedes1977 (at) *nospam* gmail.com (steve)
Groupes : comp.lang.cDate : 01. May 2024, 04:36:02
Autres entêtes
Message-ID : <87ttji19wd.fsf@gmail.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Gnus/5.13 (Gnus v5.13)
i@fuzy.me writes:
Lawrence D'Oliveiro <ldo@nz.invalid> 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.