Click here to Skip to main content
16,020,182 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hello all,

I am porting some C# code to C++ and there is a particular bit that has me a bit perplexed. The code is as follows:

C#
byte [,,] data = new byte[d,h,w];
int i=0;

for (int z = 0; z < d; z++)
{
   for (int y = 0; y < h; y++)
   {
     for (int x = 0; x < w; x++)
    {
      data[z,y,x]=bytes[i++];
    }
  }
}

So, the variable bytes contains data that I have read from the file. Normally, I would calculate the linear index as follows:

C#
index = (z*h+y)*w+x;


However, this seems to be not be the right thing in this case. I was wondering if someone knows if I am doing something obviously wrong...

Thanks,

Keith
Posted
Updated 7-Dec-11 14:26pm
v2
Comments
lewax00 7-Dec-11 17:23pm    
What exactly is going wrong? Hard to pinpoint the problem without a little more detail.
Sergey Alexandrovich Kryukov 7-Dec-11 18:30pm    
Exactly. What is that?
--SA
[no name] 7-Dec-11 20:26pm    
EDIT: added code block

1 solution

I think you are talking about the challenges to migrate C# features into C++. If itz so, you can write work around method for bytes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900