473,398 Members | 2,125 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,398 software developers and data experts.

Pointer Issues why can't I do this!

Consider:

struct myStructA
{
public unsafe fixed byte pA[10];
}

struct myStructB
{
public unsafe fixed byte pB[10];
}

unsafe class test
{
myStructA* A;
myStructB* B;

public void movePointer()
{
A->pA = B->pB;
}
}

The Compiler informs me The left-hand side of an assignment must be a
variable, property or indexer

Of course I could access the array using array notation, but that
would be longer than using pointer notation.

I have tried the same sort of thing using native C++ and that lets me
do it. Is there away I can get around this issue?
Nov 14 '08 #1
5 4741
On Nov 14, 11:02*am, bozzzza <bozz...@googlemail.comwrote:
* * * * * * A->pA = B->pB;
Is there away I can get around this issue?

Try "." instead of "->" ;-)
Nov 14 '08 #2
Lee
There is a deeper issue with your code.

If you replace A->pA = B->pB
with a simple assignment: var X = B->pB

Then if you place a breakpoint on this line, you will find that "*B =
Cannot dereference 'B'. The pointer is not valid." and that its
address is 0x00000000

L. Lee Saunders
http://oldschooldotnet.blogspot.com

Nov 14 '08 #3
bozzzza wrote:
Consider:

struct myStructA
{
public unsafe fixed byte pA[10];
}

struct myStructB
{
public unsafe fixed byte pB[10];
}

unsafe class test
{
myStructA* A;
myStructB* B;

public void movePointer()
{
A->pA = B->pB;
}
}

The Compiler informs me The left-hand side of an assignment must be a
variable, property or indexer

Of course I could access the array using array notation, but that
would be longer than using pointer notation.

I have tried the same sort of thing using native C++ and that lets me
do it. Is there away I can get around this issue?
They are not an arrays, they are fixed size buffers. Are you trying to
use arrays?

--
Göran Andersson
_____
http://www.guffa.com
Nov 15 '08 #4
Not trying to use arrays, using fixed size buffers, my point was I can
access the buffer using array notation as a work around to the
problem.

I have re-written my last example to there is something to de-
reference, hopefully it's a bit clearer of what I mean:

struct myStructA
{
public unsafe fixed byte pA[10];
}

public unsafe class test
{
public void movePointer()
{
myStructA* A;

fixed (byte* y = new byte[10])
{
y[0] = 1;

//Example 1
//Does not work, (The left-hand side of an assignment
must be a variable, property or indexer message)
A->pA = y;

//Example2 works fine, but I really want the address
of the fixed size buffer to be stored in the Struct
byte* x = y; //Works ok

//Example3
//Works ok if using array notation on the fixed size
buffer, but that would mean iterating through the buffer.
//Rather than just assigning an address
A->pA[0] = y[0];
}
}
}

Nov 15 '08 #5
bozzzza wrote:
Not trying to use arrays, using fixed size buffers, my point was I can
access the buffer using array notation as a work around to the
problem.

I have re-written my last example to there is something to de-
reference, hopefully it's a bit clearer of what I mean:

struct myStructA
{
public unsafe fixed byte pA[10];
}

public unsafe class test
{
public void movePointer()
{
myStructA* A;

fixed (byte* y = new byte[10])
{
y[0] = 1;

//Example 1
//Does not work, (The left-hand side of an assignment
must be a variable, property or indexer message)
A->pA = y;

//Example2 works fine, but I really want the address
of the fixed size buffer to be stored in the Struct
byte* x = y; //Works ok

//Example3
//Works ok if using array notation on the fixed size
buffer, but that would mean iterating through the buffer.
//Rather than just assigning an address
A->pA[0] = y[0];
}
}
}
You can't store an address in the structure as there is nowhere to store
any address. The structure only contains the fized size buffer, and
there is no pointer to it.

If you want to put some bytes in the structure, you have to put them
bytes there one by one. Perhaps the Array.Copy can be used to copy the
bytes, but that will also do a byte by byte copy.

--
Göran Andersson
_____
http://www.guffa.com
Nov 15 '08 #6

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

Similar topics

5
by: dis | last post by:
I've been going through my code and clearing away some of the compiler warnings that i'm generating and i've come across areas where i cast pointers to integer values. The Visual Studio compiler...
3
by: Robert Street | last post by:
Hi! I'm rather new at c++ and I'm totally confused with this kind of typecasting: typedef signed char int8_t; typedef signed short int16_t; typedef struct broadcast_hdr {
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
7
by: red floyd | last post by:
Given function pointer, say void (*func)(void*), what's the best way to display it on an iostream? as far as I can tell, there is no default overload for operator<<, and a function pointer...
9
by: Juggernaut | last post by:
I am trying to create a p_thread pthread_create(&threads, &attr, Teste, (void *)var); where var is a char variable. But this doesnt't work, I get this message: test.c:58: warning: cast to pointer...
16
by: Dave | last post by:
I'm having a problem trying to set up code in VB to handle the case where an argument in an API definition is defined as a pointer to a pointer. An excerpt from the API's definition is: void...
40
by: Steve Rencontre | last post by:
I can't for the life of me see how to do pointer-to-member when the member is actually part of an embedded structure. That is, if I have: struct S1 { int a; }; struct S2 { S1 s; int b; }; ...
7
by: Mohan | last post by:
Hi, What are the advantages/disadvantages of using a pointer instead of Reference in the Copy Constructor ? For Example, Writing the Copy constructor for the Class "Temp" as below, ...
8
by: Serve Laurijssen | last post by:
Consider the following code char *p1 = malloc(10); char *p2 = malloc(10); if (p1 p2) puts("bigger"); free(p1); if (p1 p2)
9
by: Dave Stallard | last post by:
Pardon if this is the wrong newsgroup for this question, and/or if this question is naive. I have a multi-threaded Windows application in which certain variables/object fields are shared: one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.