0

Hi,

I want a char array to point the memory location, which is pointed by a char pointer, without memcpy. I mean I do not need to copy all the elements again to another location

typedef struct
{
     long size;
     char data[1000];
}bulk;
 
bulk blob;

this doesn't work :

blob.data = (char *) ucBufrMessage;

it says;
error: incompatible types in assignment

Note : ucBufrMessage is an unsigned char pointer, pointing to a memory location which is full of assigned values.

4
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Hamrick
0

So why not make the member of the struct to be unsigned char *data; Then you'll be able to perform the assignment without any casting.

0

The following changes will work
typedef struct
{
long size;
char * data[1000];
}bulk;

bulk blob;

blob.data[0] = &ucBufrMessage;

0

The following changes will work
typedef struct
{
long size;
char * data[1000];
}bulk;

bulk blob;

blob.data[0] = &ucBufrMessage;

That's not any different from this, except it wastes 999 pointers.

typedef struct
{
     long size;
     char *data;
}bulk;

bulk blob;

blob.data = &ucBufrMessage;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.