'malloc' attribute?

Joseph S. Myers jsm28@cam.ac.uk
Wed Feb 26 23:59:00 GMT 2003


On Wed, 26 Feb 2003, Chris Lattner wrote:

> int * restrict foo();
> int *foo2() __attribute__((malloc));
> 
> ... is the test I intended, and is, in fact, accepted by gcc.  So, is
> there any difference between these two declarations?

restrict is only meaningful when an *object* is of restricted pointer type
(6.7.3.1).  Insofar as a function return value is an object at all, it
isn't usefully one for the purposes of restricted pointers (can't be
modified or accessed after the next sequence point, 6.5.2.2#5).  (Don't
confuse this with the example in 6.7.3.1#12: the structure returned
contains a restricted pointer, the exception to the rules on assignment of
restricted pointers allows this to pass out of the function, but the
calling function is optimised on the basis of the structure object in the
calling function containing a restricted pointer, not on anything about
the return value.  If you assign the return value of a function to a
restricted pointer in the calling function, you get an effect like
attribute malloc - but not if you just make the return type restricted.)

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc mailing list