473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Assigning a pointer to an array

My C skills are rather meager so forgive me if I do not express my question
clearly enough. Here is a struct that is declared in Windows:

typedef struct _REPARSE_GUID_DATA_BUFFER
{
DWORD ReparseTag;
WORD ReparseDataLength;
WORD Reserved;
GUID ReparseGuid;
struct {BYTE DataBuffer[1]; } GenericReparseBuffer;
} REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;

Now I'm going to show my attempt at assigning to "DataBuffer". This code is
written in Eiffel but the part inside of the square brackets ([]) is C code
except you will see some "$" symbols which you can ignore:

set_c_generic_reparse_buffer_data_buffer_pointer (a_item, v: POINTER) is
external
"C inline use <Windows.h>"
alias
"[
{
PREPARSE_GUID_DATA_BUFFER itm;
BYTE* db;
itm = $a_item;
db = $v;
&((itm->GenericReparseBuffer).DataBuffer) = db;
}
]"
end

Line 5 of the C code part is where I attempt to assign the array
"DataBuffer[]" in the struct "GenericReparseBuffer" which is a member of the
struct "REPARSE_GUID_DATA_BUFFER". My Eiffel compiler translates the Eiffel
code into C and uses MSVC++ to compile it. The C compiler gives me this
error:

error C2106: '=' : left operand must be l-value

I'm hoping I can get some assistance with this. Sorry about the Eiffel code
but this is a problem with the C part.

Regards
Chris Saunders

Jun 27 '08 #1
3 2766
Chris Saunders <ev**@mountaincable.netwrote:
My C skills are rather meager so forgive me if I do not express my question
clearly enough. Here is a struct that is declared in Windows:
typedef struct _REPARSE_GUID_DATA_BUFFER
{
DWORD ReparseTag;
WORD ReparseDataLength;
WORD Reserved;
GUID ReparseGuid;
struct {BYTE DataBuffer[1]; } GenericReparseBuffer;
} REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;
Now I'm going to show my attempt at assigning to "DataBuffer". This code is
written in Eiffel but the part inside of the square brackets ([]) is C code
except you will see some "$" symbols which you can ignore:
set_c_generic_reparse_buffer_data_buffer_pointer (a_item, v: POINTER) is
external
"C inline use <Windows.h>"
alias
"[
{
PREPARSE_GUID_DATA_BUFFER itm;
BYTE* db;
itm = $a_item;
db = $v;
&((itm->GenericReparseBuffer).DataBuffer) = db;
}
]"
end
Line 5 of the C code part is where I attempt to assign the array
"DataBuffer[]" in the struct "GenericReparseBuffer" which is a member of the
struct "REPARSE_GUID_DATA_BUFFER". My Eiffel compiler translates the Eiffel
code into C and uses MSVC++ to compile it. The C compiler gives me this
error:
error C2106: '=' : left operand must be l-value
The line

&((itm->GenericReparseBuffer).DataBuffer) = db;

doesn't make sense. You basically try to say that the address of
of the 'DataBuffer' array is supposed to be the same as the one
strored in 'db'. But that can't work. 'DataBuffer' is part of the
struct and you can't say it should suddenly be somewhere else.
It's not really clear to me if you want to assign what 'db' is
pointing to to that array, in which case you would have to use

itm->GenericReparseBuffer.DataBuffer[ 0 ] = *db;

But I don't see why you would defined 'DataBuffer' as an array
with a single element if you want store the value of a single
BYTE there.

It could also be that you in principle mean what you're saying
with the "make the address the same as that of 'db'. In that case
your structure isn't suitable for the purposse, you would need

typedef struct _REPARSE_GUID_DATA_BUFFER
{
DWORD ReparseTag;
WORD ReparseDataLength;
WORD Reserved;
GUID ReparseGuid;
struct { BYTE *DataBuffer; } GenericReparseBuffer;
} REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;

and then simply say

itm->GenericReparseBuffer.DataBuffer = db;

Of course, the address stored there only makes sense as long
as what 'db' points to still exists. But if you want to create
a copy of what 'db' points to then you need to first of all
know the number 'len' of bytes 'db' points to and then allocate
memory and copy what 'db' points to, a la

itm->GenericReparseBuffer.DataBuffer = malloc( len );
memcpy( itm->GenericReparseBuffer.DataBuffer, db, len );

In that case you're responsible for getting rid of the
memory when it isn't used anymore or at least when what-
ever 'itm' points to goes out of scope or becomes de-
allocated.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jun 27 '08 #2
Chris Saunders wrote:
struct {BYTE DataBuffer[1]; } GenericReparseBuffer;
DataBuffer is an array of size 1.
&((itm->GenericReparseBuffer).DataBuffer) = db;
And here you try to assign to the array. You can't do that. If you want
DataBuffer to be assignable, make it a pointer.
struct {BYTE *DataBuffer; } GenericReparseBuffer;
Line 5 of the C code part is where I attempt to assign the array
"DataBuffer[]" in the struct "GenericReparseBuffer" which is a member of
the struct "REPARSE_GUID_DATA_BUFFER". My Eiffel compiler translates
the Eiffel code into C and uses MSVC++ to compile it.
Your Eiffel compiler seems to be defective!
Jun 27 '08 #3
My thanks to Jens Thoms Toerring and Mark McIntyre for responding. Sorry I
took awhile but I've been very busy. Thanks again.

Regards
Chris Saunders

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Dave | last post by:
Hello all, Please consider the code below. It is representative of a problem I am having. foo_t needs to contain a bar_t which is a class without a copy constructor or operator=. It is not...
14
by: Eric Bantock | last post by:
Very basic question I'm afraid. Once an array has been declared, is there a less tedious way of assigning values to its members than the following: myarray=8; myarray=3; myarray=4; myarray=0;...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
25
by: Sourav | last post by:
Suppose I have a code like this, #include <stdio.h> int *p; void foo(int); int main(void){ foo(3); printf("%p %d\n",p,*p);
8
by: mast2as | last post by:
I almost apologize to ask this question but I have been starting at this code for a bit of time and don't understand what's wrong with it. I am not arguing about the fact it's good or not coding,...
9
by: Peithon | last post by:
Hi, This is a very simple question but I couldn't find it in your FAQ. I'm using VC++ and compiling a C program, using the /TC flag. I've got a function for comparing two strings int...
9
by: J. Peng | last post by:
I just thought python's way of assigning value to a variable is really different to other language like C,perl. :) Below two ways (python and perl) are called "pass by reference", but they get...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.