I have the following :
logic [15:0] tb_real_din, tb_image_din;
int unsigned counter;
//write proc
initial begin
tb_last_dvalid = 1'b0;
tb_we = 1'b0;
#80ns;
for (int i = 0 ; i <= 32; i++)
begin
counter = counter+1;
tb_real = counter;
tb_image = counter;
if (i == 32)
tb_last_dvalid = 1'b1;
#8ns;
tb_we = 1'b1;
#8ns;
tb_we = 1'b0;
tb_last_dvalid = 1'b0;
end
end // initial begin
I got the following error:
Illegal reference to net "tb_real".
How can I convert int unsigned to array logic?
Your problem is nothing to do with converting between types. Your problem is probably because you have not declared tb_real. Anything undeclared in System-verilog defaults to being a 1-bit wire; a wire is a kind of net and it is illegal to assign to nets from initial, always or final blocks. Hence, your error message.
I say "probably" because you have not give an MCVE.
Related
I am using Predefined style -> Allman braces and this is the strange behavior I get:
// this looks good
int edges = 0;
long variable_2 = 0;
AnotherLong obj = 0;
// this looks bad way off
int edges = 0;
long variable_1;
long variable_2 = 0;
AnotherLong obj = 0;
The variables should be grouped in columns, however an empty line should indicate a new "block" of code, right ? On the first case int edges = 0; is aligned fine, why not in the second case ? How can I fix that ?
Edit: Created a bug report
After getting my first problem solved at C++ zLib compress byte array i faced another problem
void CGGCBotDlg::OnBnClickedButtonCompress()
{
// TODO: Add your control notification handler code here
z_const char hello[256];
hello[0] = 0x0A;
hello[1] = 0x0A;
hello[2] = 0x0A;
hello[3] = 0x0A;
hello[4] = 0x0A;
hello[5] = PKT_END;
hello[6] = PKT_END;
hello[7] = PKT_END;
Byte compr[256];
uLong comprLen = sizeof(compr);
int ReturnCode;
ReturnCode = Compress(compr, comprLen, hello, Z_DEFAULT_COMPRESSION);
g_CS.Send(&compr,comprLen);
}
int CGGCBotDlg::Compress(Byte Compressed[], uLong CompressedLength, CHAR YourByte[], int CompressionLevel)
{
int zReturnCode;
int Len;
for (int i = 0 ; i <= 10240 ; i++)
{
if (YourByte[i] == PKT_END && YourByte[i+1] == PKT_END && YourByte[i+2] == PKT_END)
{
Len = i - 1;
break;
}
}
uLong Length = (uLong)(sizeof(YourByte) * 1.0001) + 12;
zReturnCode = compress2(Compressed, &Length, (const Bytef*)YourByte, Len,CompressionLevel);
return zReturnCode;
}
Im trying to compress hello[] wich is actually 5 bytes (I want to compress first 5 bytes)
The expected result after compressing is : 0x78,0x9C,0xE3,0xE2,0x02,0x02,0x06,0x00,0x00,0xCE,0x00,0x33
But what I get after compressing is just the first 4 bytes of expected result and another bytes are just something else.
And my second problem is that i want to replcae 256 in Byte compr[256] with the exact number of bytes after decompressing original buffer (which is 12 in my case)
Would be great if someone correct me
Thanks
this line is wrong:
Len = i - 1;
because when i is 5, you do Len = i - 1; so len will be 4, but you want compress 5 bytes. just use:
Len = i;
another problem comprLen is never been assigned a value. In Compress(Byte Compressed[], uLong CompressedLength..), itCompressedLength is not used. I assume you want its value back. you should define like this:
Compress(Byte Compressed[], uLong& CompressedLength..)
and change the line to use CompressedLength instead of using length:
zReturnCode = compress2(Compressed, &CompressedLength, (const Bytef*)YourByte, Len,CompressionLevel);
I have difficulties while converting the following matlab line into C++:
for i=1:height
for j=1:width
if (match == 0)
[min_w, min_w_index] = min(w(i,j,:));
mean(i,j,min_w_index) = double(data(i,j));
sd(i,j,min_w_index) = sd_init;
end
rank = w(i,j,:)./sd(i,j,:);
rank_ind = [1:1:C];
end
end
Especially I don't know how to covert the "min_w_index" part. Could someone help me on this point?
Most common solution for min function in such case is
int min_w = w[i][j][0];
int min_w_index = 0;
for (k = 1; k < maxk; k++)
if (w[i][j][k] < min_w)
{
min_w = w[i][j][k];
min_w_index = k;
}
Don't forget that C++ has zero-based index, but Matlab one-based. I already see problem in your comment.
I am working in VC++ 2008, and am trying to allocate a multi-dimensional array of chars to do some file work. I know that whenever an array is allocated all the members of the array should be initialized usually in a successive order. what I have currently is this.
char ** thing = new char *[lineY];
for (int ii = 0; ii < lineY; ii++){
thing[ii] = new char[lineX];
}
... // working with array
// deleting each part of the array.
for (int ii = 0; ii < lineY; ii++){
delete [] thing[ii];
}
delete [] thing;
the problem that I am running into is that if I add the array to the watch list, or put a break right after its been allocated the debugger states that the array is equal to a number like 51, or 32, and not a block of space with indexes, and values, but when I try to initialize the values of each index by making my allocation this:
char ** thing = new char *[lineY];
for (int ii = 0; ii < lineY; ii++){
thing[ii] = new char[lineX];
for (int jj = 0; jj < lineX; jj++){
thing[ii][jj] = '';
}
}
edit: the compiler throws "C2137 empty character constant" am I doing something wrong?
edit: read msdn on the error number, and found answer
You cannot write thing[ii][jj] = '' because '' is an empty character constant which isn't allowed. Try replacing '' with something like ' ' (with the space between 's)
Are lineX and lineY compile-time constants? In that case:
std::array<std::array<char, lineX>, lineY> thing;
Otherwise:
std::vector<std::vector<char> > thing(lineY, std::vector<char>(lineX));
this should be the final part of my integer class, and it seems to be very easy, and yet, something is wrong. is this code correct for multiplication using 2 deques?
// 0x12345 = {0x01, 0x23, 0x45}
integer operator*(integer rhs){
// long multiplication
unsigned int zeros = 0;
std::deque <uint8_t> row;
std::deque <std::deque <uint8_t> > temp;
integer out = 0;
for(std::deque <uint8_t>::reverse_iterator i = value.rbegin(); i != value.rend(); i++){
row = std::deque <uint8_t>(zeros++, 0); // zeros on the right hand side
uint8_t carry = 0;
for(std::deque <uint8_t>::reverse_iterator j = rhs.value.rbegin(); j != rhs.value.rend(); j++){
uint16_t prod = (uint16_t(*i) * uint16_t(*j)) + carry;// multiply through
row.push_front((uint8_t) prod);
carry = prod >> 8;
}
if (carry != 0)
row.push_front(carry);
out += integer(row);
}
return out;
}
it is giving me 4931550625 ^ 2 -> 24248133972899962689. assuming that the operator+ is correct, which i seems to be, is there some other explanation of why this is wrong
edit: i updated the code according to wxffles, but i think i did it wrong, since im still getting 2424..., and for 0x25 * 0x25 im getting 89 (decimal)
edit2: the correct code is posted
I think you are missing the last carry. Do you not need:
row.push_front(carry);
just before you add the row to out?