Newbie problem with arrays 
Author Message
 Newbie problem with arrays

Hi there,

We'd like to declare a function that returns an array.

Face rekursion(Face flaeche, int rek){
...do something in here....

return flaeche;
/*4 Points that declare a Face should be returned here */

Quote:
}

Face is declared like that:
typedef Point Face[ 4];

Point is declared like that:
typedef float Point[3];

The problem is that we get the following error message:
'rekursion' declared as function returning an array
and a warning: return makes integer from pointer without a cast

Petra & Laura



Wed, 07 May 2003 03:00:00 GMT  
 Newbie problem with arrays

Quote:

> Hi there,

> We'd like to declare a function that returns an array.

> Face rekursion(Face flaeche, int rek){
> ...do something in here....

> return flaeche;
> /*4 Points that declare a Face should be returned here */
> }

> Face is declared like that:
> typedef Point Face[ 4];

> Point is declared like that:
> typedef float Point[3];

> The problem is that we get the following error message:
> 'rekursion' declared as function returning an array
> and a warning: return makes integer from pointer without a cast

Arrays cannot be used directly as return values from functions.

The problem can be approached in a number of possible ways;
* Pass an empty array to function as another argument, to be
  filled in by the function.
* Use a structure to hold the array - a struct can be returned.
  e.g.
    typedef float Point[3];
    typedef struct { Point pnt[4]; }Face;

Hope this helps

Malcolm Kay



Thu, 08 May 2003 12:28:54 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbie Array Problem - how to strncpy from an array of char

2. Read file to array problem (Newbie for those wishing to avoid)

3. newbie char array assignment problem

4. Newbie Function/2D array problem

5. Newbie Array/Scanf Problem

6. Newbie Array Problem - how to strncpy fr

7. Newbie Array Problem BC/C++ v4.0

8. Arrays and arrays of strings problem

9. Help : Problems with Arrays of Arrays

10. problem realloc array inside array of struct

11. problem realloc array inside array of struct

12. how do I pass arrays as parameters to functions - newbie

 

 
Powered by phpBB® Forum Software