Error: Expression is not assignable C++ struct

I am writing a normal bandwidth kernel in C++ for FPGA, which is reading something from host memory and writing it back to different location in host.
I'm using structs, one of whose elements is addresses for input and output buffers. High-level synthesis tool is giving error for the last line in the following code.

struct addr_struct {
ap_uint<64> address;
ap_uint<32> size;
ap_uint<16> type;
ap_uint<16> flags;
};
struct addr_struct CA_INPUT;
struct addr_struct CA_OUTPUT;
din_mem = 0x00;
dout_mem = 0x00;
ap_uint<32> i;
ap_uint<512> temp;
ap_uint<512> *din_mem;
ap_uint<512> *dout_mem;
for(i=0;i<size;i++)
{
temp= (ap_uint<512> *)(din_mem + CA_INPUT.address + i*64);
(ap_uint<512> *)(dout_mem + CA_OUTPUT.address + i*64) = temp;
}
Last edited on
1
2
temp = *(ap_uint<512> *)/*...*/;
*(ap_uint<512> *)/*...*/ = temp;
?
Last edited on
What are the data types for din_mem , dout_mem, and temp?
And what is an ap_uint<512>?
Solution by helios seems syntactically logical.

temp= (ap_uint<512> *)(din_mem + CA_INPUT.address + i*64);
(ap_uint<512> *)(dout_mem + CA_OUTPUT.address + i*64) = temp;

Lets be more abstract:
1
2
3
4
5
6
7
T * pa = ...
U bb = ...
V cc = ...

T dd = ???_cast< T* >( pa + bb + cc * 64 );

???_cast< T* >( pa + bb + cc * 64 ) = dd; // error 

The pa is a pointer (T*), while bb, cc and 64 are not.
The bb and cc presumably behave like integers and in that case the type of the pa + bb + cc * 64 would be T*.
1
2
3
T* bar;
T  foo;
foo = (T*)(bar); // hmmm 

An explicit (C-style) cast from T* into T* does seem unnecessary.
1
2
3
4
T* bar;
T  foo;
foo = bar; // scary
bar = foo; // scary 


The pa + bb + cc * 64 may be an address, but it is not a named variable. Assignment to unnamed temporary pointer ...
Now that you mention it, keskiverto, I'm wondering about OP's intent.
1
2
//ap_uint<512> *dout_mem;
din_mem + CA_INPUT.address + i*64
This looks like the intent might have been
1
2
//ap_uint<512> *dout_mem;
(byte *)din_mem + CA_INPUT.address + i*64
It seems to work. (din_mem + CA_INPUT.address + i*64) is indeed an address. But it's not incrementing the addresses by 64. For the first 64 bytes, temp gets the value which is pointed by input address. But for subsequent iterations of for loop, temp remains 0.
Is there a different way to increment the addresses?
 
(byte *)din_mem + CA_INPUT.address + i*64
or
 
(uintptr_t)din_mem + CA_INPUT.address + i*64
Topic archived. No new replies allowed.