Problem passing char * to a function where it is assigned its value 
Author Message
 Problem passing char * to a function where it is assigned its value

I am trying to pass a char * to a function where upon some processing of
data the value of the pointer is set to the address of an array of char
embedded in a struct.  This is on an embedded system, so I have limited
debug capability.

code fragment:(s):

    unsigned char *robstr;

    do // Get ack message on COM0
       status = GetMsgCOM0( &robstr );
       if( ack_time >= 300 ) timeout = 1;
    }while(( status == -1 ) && ( timeout == 0 ));

S_BUFFER com0_msg_buf;

char GetMsgCOM0( char *buffer )

    // process...
    // if success
           *buffer =;


where the struct is:

struct small_buffer_type
  unsigned char storage[256];   /* Buffer storage array */
  unsigned char size;
  unsigned char in;   /* Input index */
  unsigned char out;  /* Output index */
  unsigned char over; /* Buffer overflow flag */


typedef struct small_buffer_type S_BUFFER;

At the point where GetMsgCOM0 is entered, I sent the value of buffer out the
serial port.  It had the address of robstr as its value, which seems right.
The problem comes when I try to assign the value of & to
robstr through buffer.

I don't want to alter the character string pointed to by  I just want to access it as though it were an array
without having  com0_msg_buf be a global variable.

Do I need to use char ** to pass a pointer to a pointer to char, so I can
assign the address of the pointer?

Please help!
Robert Allen
Development Engineer
Electrosonic Systems, Inc.

Fri, 07 Jul 2000 03:00:00 GMT  
 Problem passing char * to a function where it is assigned its value

On Mon, 19 Jan 1998 16:19:22 -0600, Robert Allen

[ much snippage ]

>struct small_buffer_type
>  unsigned char storage[256];   /* Buffer storage array */
>  unsigned char size;
>  /* ... */
>typedef struct small_buffer_type S_BUFFER;
>S_BUFFER com0_msg_buf;

>    unsigned char *robstr;
>    status = GetMsgCOM0( &robstr );

>char GetMsgCOM0( char *buffer )
>  /* ... */
>           *buffer =;
>    return;

There are at least two errors.  First, your function definition expects
a pointer to character, yet you are passing in the address of the
pointer of a character.  Second, you are assigning something of type
array of char (which decays to a pointer to char) to a something of type

Try redeclaring your function to expect a pointer to a pointer to char:

char GetMsgCOM0( char **buffer )
  /* ... */
           *buffer =;


--        Washington University in Saint Louis

- Show quoted text -

>>>>>>>>>>>>> I use *SpamBeGone* <URL:>

Sat, 08 Jul 2000 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. problem assigning char* to char*

2. assigning the value of a char to a string (newbie)

3. assigning int value to char

4. Assigning char * value to a CString object

5. Problem with function passing value..Help!

6. CC problem: passing/receiving values to functions

7. Passing a char array[n] to a function expecting a char*

8. How to assign the value in this function?

9. Problem assigning function to function pointer

10. Passing a char* as argument or as a return value

11. Pass string or char[10] value Using PostMessage

12. Problems assigning const fields in a class to an initial value


Powered by phpBB® Forum Software