Returning Pointer To Pointer From Function 
Author Message
 Returning Pointer To Pointer From Function

I would appreciate some advice on how to correctly write a function
prototype, and how to use the variable that was passed.  I'll explain
what the situation is.  Before I gave up on this, I was getting syntax
errors no matter what I tried.

At the top of the program, I set up a define
"define TYPE_16BIT_UNSIGNED unsigned small".  In a function, I used
malloc to get a pointer to an array of TYPE_16BIT_UNSIGNED.  This was a one
dimensional array which stored a two dimensional image, one row after the
other.  In the function, I used malloc to allocate memory for an array of
pointers to variables of type TYPE_16BIT_UNSIGNED.  Each element in the
pointer array was then initialized to point to the first element of a row
in the first array.  What I couldn't figure out was how to set up the
function prototype so that I could return the pointer to the image array,
and the pointer to the array of pointers.

If the variables were local to the function, I think that the definitions
would be similar to:

TYPE_16BIT_UNSIGNED *image_ptr;  /* pointer to image array */
TYPE_16BIT_UNSIGNED **image_row_ptr;  /* pointer to array of row pointers */

After initialization, I could access elements in the image array by writing:

image_row_ptr[i][j] = 0;

But, the compiler didn't seem to like me defining the image_row_ptr in
the function prototype as:

TYPE_16BIT_UNSIGNED ***image_row_ptr

Does anyone have a suggestion?  Please send it to me by e-mail if you
do.  Thanks.

--

============================================================================

Systems Analyst II                     | WWW: http://www.*-*-*.com/ ~clscott/
Computing Services - SUB203C           | Voice: (501) 569-3342
University of Arkansas at Little Rock  |
Little Rock, AR  72204                 |
============================================================================



Tue, 28 Sep 1999 03:00:00 GMT  
 Returning Pointer To Pointer From Function

Quote:

> I would appreciate some advice on how to correctly write a function
> prototype, and how to use the variable that was passed.  I'll explain
> what the situation is.  Before I gave up on this, I was getting syntax
> errors no matter what I tried.

[Rest of problem description snipped]

You will get a lot of hints on pointer usage and the solution to your
problem from the FAQ to this newsgroup, which you should have read
before
posting here anyway.

You can get the FAQ at http://www.eskimo.com/~scs/C-faq/top.html or
at ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/C-FAQ-list and it gets
posted to this newsgroup and to news.answers regularly (at the
beginning of each month).

Stephan



Fri, 01 Oct 1999 03:00:00 GMT  
 Returning Pointer To Pointer From Function

: I would appreciate some advice on how to correctly write a function
: prototype, and how to use the variable that was passed.  I'll explain
: what the situation is.  Before I gave up on this, I was getting syntax
: errors no matter what I tried.

: At the top of the program, I set up a define
: "define TYPE_16BIT_UNSIGNED unsigned small".  In a function, I used
: malloc to get a pointer to an array of TYPE_16BIT_UNSIGNED.  This was a one
: dimensional array which stored a two dimensional image, one row after the
: other.  In the function, I used malloc to allocate memory for an array of
: pointers to variables of type TYPE_16BIT_UNSIGNED.  Each element in the
: pointer array was then initialized to point to the first element of a row
: in the first array.  What I couldn't figure out was how to set up the
: function prototype so that I could return the pointer to the image array,
: and the pointer to the array of pointers.

: If the variables were local to the function, I think that the definitions
: would be similar to:

: TYPE_16BIT_UNSIGNED *image_ptr;  /* pointer to image array */
: TYPE_16BIT_UNSIGNED **image_row_ptr;  /* pointer to array of row pointers */

: After initialization, I could access elements in the image array by writing:

: image_row_ptr[i][j] = 0;

: But, the compiler didn't seem to like me defining the image_row_ptr in
: the function prototype as:

: TYPE_16BIT_UNSIGNED ***image_row_ptr

: Does anyone have a suggestion?  Please send it to me by e-mail if you
: do.  Thanks.

: --

: ============================================================================

: Systems Analyst II                     | WWW: http://www.ualr.edu/~clscott/
: Computing Services - SUB203C           | Voice: (501) 569-3342
: University of Arkansas at Little Rock  |
: Little Rock, AR  72204                 |
: ============================================================================

--
***************begin r.s. response******************

        try using a
                typedef
        rather than
                #define
        for this ...

***************end r.s. response********************
Ralph Silverman



Fri, 01 Oct 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Pointer to function returning pointer to function returning...

2. Question about signal()/pointers to functions that return pointers to functions

3. How to use (pointer to function), and function and pointer to (pointer to function)

4. Pointer Functions and Pointers to Pointer Functions

5. Pointers: return of pointer to array of pointers to main

6. Can function returning pointer return negative integers?

7. Function returning a function-pointer - how to prototype ?

8. Declaring static function returning pointer to extern function

9. About function that returns function pointer

10. Function returning pointers to functions (repost)

11. Function returning pointers to functions

12. (member) function returning pointer to functions like itself?

 

 
Powered by phpBB® Forum Software