[rescue] Cooling (Long Message, sorry)

Big Endian bigendian at mac.com
Wed Apr 17 09:22:04 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.
>

I've used picky compilers in the past (metrowerks, Mr C/MPW)

>  > >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.

malloc()== new.  fmat4x4 newmat = new fmat4x4;

daniel
-- 
-----------------------------------------------------------------
"Fragile. Do not drop." -- Posted on a Boeing 757.



More information about the rescue mailing list