Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ void * my_malloc(size_t size) [[gnu::malloc]] [[gnu::malloc(my_free, 1)]];
In `__attribute__` keyword syntax:

~~~c
void my_free(void *ptr);

// Denotes that my_malloc will return with a dynamically allocated piece of memory which must be freed using my_free.
void *my_malloc(size_t size) __attribute__ ((malloc, malloc (my_free, 1)));
void *my_malloc(size_t size) __attribute__ ((malloc, malloc (my_free, 1))) { … }
~~~

Note that to benefit both from the associated optimizations and improved detection of memory errors functions should be marked with _both_ the form of the attribute without arguments and the form of the attribute with one or two arguments. [[Extended example at Compiler Explorer](https://godbolt.org/z/bc97ahbnd)]
Expand Down Expand Up @@ -365,13 +363,6 @@ In C++11 / C23 attribute syntax:
~~~c
// Denotes that fatal will never return
void fatal () [[noreturn]];

void
fatal (...)
{
... /* Print error message. */ ...
exit (1);
}
~~~

In `__attribute__` keyword syntax:
Expand Down