This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 'malloc' attribute?


On Wed, 26 Feb 2003, Joseph S. Myers wrote:
> 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

For reference, I'm looking at:
http://wwwold.dkuug.dk/JTC1/SC22/WG14/www/docs/n897.pdf

I'm not sure what you mean by *object* in this context.  In the following
example:

listnode *restrict createNode() {
  listnode *New = (listnode*)malloc(sizeof(listnode));
  New->Next = 0;
  New->Data = 0;
  return New;
}

void test(listnode * restrict A) {
  listnode *B = createNode();

}

I'm not sure how A & B are different in the context of "test".  My reading
of section 6.7.3.1 of the rational seems to indicate that A and B are
different.  Although it doesn't say anything about the return value of a
function, it says these things:

File scope:
"A translator can assume that a file scope restrict-qualified pointer is
the sole initial means of access to an object, much as if it were the
declared name of an array."

Function parameter:
"A translator can assume that a restrict-qualified pointer that is a
function parameter is, at the beginning of each execution of the function,
the sole means of access to an object."

Block scope:
"A translator can assume that a restrict-qualified pointer declared with
block scope is, during each execution of the block, the sole initial means
of access to an object."

Structure member:
"The restrict qualifier can be used in the declaration of a structure
member. A translator can assume, when an identifier is declared that
provides a means of access to an object of that structure type, that the
member provides the sole initial means of access to an object of the type
specified in 25 the member declaration."

Again, they don't mention the return value of a function, but it seems a
simple extrapolation that the return value of "createNode()" above should
be treated as "the sole initial means of access to an object."

Isn't this the same as attribute(malloc)?

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]