This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
'malloc' attribute?
- From: Chris Lattner <sabre at nondot dot org>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 26 Feb 2003 17:08:16 -0600 (CST)
- Subject: 'malloc' attribute?
Apparently C99 doesn't allow declaring a function to return a 'restrict'
pointer (GCC rejects it at least), but GCC does allow you to attach the
malloc attribute to a function. It seems to me that this is the exact
same information, ie, the following two function prototypes should be
equivalent:
restrict int* foo(); // Currently rejected with -std=c99
int *foo() __attribute__((malloc));
According to the C rationale, a restrict pointer is known to not point to
anything else in the scope: a returned restrict pointer is similar,
indicating that the returned value from the function is a new logical
object. Is use of the 'malloc' attribute on a function return value
conceptually any different than declaring the returned pointer 'restrict'?
If not, then:
1. It would seem like a useful extension for the next C standard to
incorporate, allowing portable code to express the semantics of
functions like xmalloc.
2. It would seem like a useful extension to include in the gnu C dialect
until it is official.
3. It seems that code for handling A_MALLOC could be merged with the
code to handle RID_RESTRICT, possibly reducing some code
duplication.
Comments? Am I totally confused here? :)
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/