convert two dimensional array to one dimensional in C -


i have 2 dimensional array this:

ptr = (int **) malloc(size);  (i = 0; < len; i++) {     ptr[i] = (int *) malloc(size); } 

is there simple way create int *intptr array such can access values in row major order?

e.g.: if ptr points n*n array, want first item of second column this: *(intptr + n)

i need conversion pass 2 dimensional array cuda kernel, want avoid pass 2 dimensional array kernel because seems quiet complicated.

no. if had allocated true 2d array of ints:

int a[size][size]; 

then answer might yes though result not portable. refer this article more array type punning information.

but accessing element in row of array requires explicitly dereferencing pointer.


Comments

Popular posts from this blog

android - Automated my builds -

ruby on rails - Difference between "Redmine on Heroku" and "Installing Redmine" documentation -

c# - Create a custom control in Corel Draw X6 using only VSTA -