[rescue] Cooling (Long Message, sorry)

Joshua D Boyd jdboyd at cs.millersville.edu
Tue Apr 16 22:29:26 CDT 2002


On Tue, Apr 16, 2002 at 11:22:57PM -0400, Big Endian wrote:
> This isn't right:
> >
> >float * test() {
> >  int x = 3;
> >  int y = 4;
> >
> >  float f[x][y];
> >
> >  return (float *)f;
> >
> >}
> 
> Ok... I'm suprised this even compiles.

Why?  You can do all sorts of coercian tricks.
 
> >Meaning, that f isn't a new memory location each time, which is a major
> >problem since instead of test() here, I was writing a function that 
> >constructs
> >a matrix that then needs to persist past the creation of the next 
> >one, and also
> >gets passed to third party libraries.
> 
> Ok... so if x and y are fixed size (say 4x4 matrix):
> 
> typedef float[4][4] fmat4x4;
> 
> fmat4x4 newmat = malloc(sizeof(fmat4x4)); //sorry... my C is showing

Yes, that absolutely works.  But the professor I'm doing this for would flip
out if he saw a malloc.  Now, perhaps it doesn't really matter, since I'm
not obliged to make this work for him, but still, there has to be an official
C++ way of doing this, and darn it, I want to know.

-- 
Joshua D. Boyd



More information about the rescue mailing list