From: Jerry <lan...@qw...> - 2006-07-28 22:16:12
|
I've had a nearly-complete thin binding of PLplot to Ada for a few weeks now, and am working on a thick binding. However, even at the thin binding level, I've encountered a problem with passing 2D Ada arrays to C. I refer the interested to this thread at comp.lang.ada (as hosted by Google): http://groups.google.com/group/comp.lang.ada/browse_thread/thread/ 6b3a3c920575b35a/193ba675e86cb69a? Being a relative Ada newbie and just learning enough C in the process to get by, I thought the gurus on the list would have the answer. However, it hasn't been forthcoming and even they seem befuzzled = befuddled + puzzled. I don't expect any Ada per se help from this post, and this is really a C question, but since there might be a vested interest from the PLplot community to have functioning Ada bindings, maybe you will humor this question: How does C map 2D arrays such as PLFLT **z to memory (e.g. plmesh)? Is this an array of pointers that then each point to the first element of a row (column??) of z, or is this simply a pointer to a pointer to z[0, 0] which merely needs to be twice de-referenced? Let me try to be even more confusing. Say z is M x N. Is the address that is pointed to by PLFLT **z the first byte of a blob of memory that is M*N*sizeof(int), with M and N used in parsing up this blob into addressable array elements? Or are there actually M pointers to M memory locations, each of which represents N array elements as a contiguous blob of memory amounting to N*sizeof(int) bytes? If the latter is true, then it seems that z would require M*N*sizeof(int) +M*sizeof(pointer) bytes, and somehow this seems weird. If the latter is true, then could one access array element i,j by an offset M + M*i + j or something like that? Note that the standard C interfaces provided by Ada deal perfectly and easily with 1D arrays. Thanks for any comments. Jerry |