<div class="gmail_quote">On Fri, Jun 10, 2011 at 20:37, James Porter <span dir="ltr"><<a href="mailto:jvporter@wisc.edu">jvporter@wisc.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":io">I honestly can't think of any case where an undefined array pointer is<br>
"safer" than a null array pointer.</div></blockquote><div><br></div><div>You are missing the point. We have two possible intents. One of them is unexpressable with the current interface. They can be unambiguously distinguished if the caller initializes a pointer that could have a zero-length return and that they will call free() on.</div>
<div><br></div><div>We want to allow the user to fill a contiguous buffer with the contents of multiple sets or with topological entities in a defined order, for example.</div><div><br></div><div>For this, they loop over the sets (perhaps much earlier in the code) and compute the number of entities in each. Then they allocate one large array. Then they loop over the sets and call iMesh_getEntities() or similar. The pointer they pass in points at the offset in the contiguous array where they want to place those entities. The allocated size may be computed as zero if there are empty sets. They will compute the start of the next segment by adding the size of this set to the </div>
<div>pointer.</div><div><br></div><div>iBase_EntityHandle *base,*p;</div><div>int i,total = 0;</div><div>for (i=0; i<nsets; i++) total += size[i];</div><div>base = malloc(sizeof(**base)*total);</div><div>for (i=0,p=base; i<nsets; p+=size[i],i++) {</div>
<div> int actual;</div><div> // The following does not want p or size[i] to be modified.</div><div> iMesh_getEntities(mesh,set[i],type,topo,&p,&size[i],&actual,&err);CHK(mesh,err);</div><div> ASSERT(size[i] != actual);</div>
<div>}</div><div><br></div></div>