473,385 Members | 1,351 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,385 software developers and data experts.

Cast to pointer to multidimensional array

Dear All,

there have been several threads on multidimensional arrays and pointers
to arrays, there is still something I could not fully understand.
(My point here I have raised already, but stayed unanswered)

Let's have an array.

float A[256];

And you would like to consider this as 32x8 matrix.
You can of course do A[32*i+j] for the (i,j)-th element, but it is
much more convenient to put it into an array form:

float (*B)[8]=(void*)A;

The (void*) here is merely to shut up the compiler (ie. to fulfil the language
constraints). B is a pointer to the first one of a series (float[8]) arrays.

Then, after using this layout of the data, I realise that I need an other
matrix format: 16x16, so I write.

float (*C)[16]=(void*)A;

So far there was no cast to a pointer to multidimensional array,
but you could actually want a 4x4x4 tensor and declare:

float (*D)[4][4]=(void*)A;

Is there any undefined behaviour in these casts or the subsequent access
to the members B[i][j] and C[i][j] or D[i][j][k] (i,j,k within bounds)?

Final question:

If my initial array is given by a restricted pointer to its first element,
how can I legally proceed to do these casts?

Szabolcs
Jun 27 '08 #1
0 4374

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

Similar topics

2
by: shane | last post by:
Ive searched a fair bit for the answer, but nothing has come up that matches what i want to do. I'm having an issue with passing and assigning pointers to multidimensional arrays. The code: ...
4
by: Kobu | last post by:
I've read the FAQ and several posts on multidimensional arrays and how their names decay to pointer to arrays (not pointer to pointers). If this is so, why does the following code fragment...
3
by: S. Nurbe | last post by:
Hi, small question concerning pointer: How do I allocate and have access to this pointer in C: float **x; such that I can work with it like an array, e.g. x?
14
by: sheroork | last post by:
Can anyone help me in getting to understand pointer to pointer with examples? Appritiate in advance. Sagar
24
by: Kavya | last post by:
int main (){ int a={{1,2,3},{4,5,6}}; int (*ptr)=a; /* This should be fine and give 3 as output*/ printf("%d\n",(*ptr)); ++ptr;
26
by: Ioannis Vranos | last post by:
Are the following guaranteed to work always as *C90* code? 1. #include <stdio.h> void some_func(int *p, const size_t SIZE) { size_t i;
7
by: lovecreatesbea... | last post by:
Is it always legal to cast expressions of type of multi-dimension array to type of pointer? Including: T to T* , T to T* , T to T* , and so on... For example: int *mtxrot1d(int *p,...
7
by: Szabolcs Borsanyi | last post by:
I know that this topic has been discussed a lot, still I'd appreciate a clear cut (and correct) answer: I pass a multidimensional array to a function, which is defined as int f(int a) { int...
14
by: Szabolcs Borsanyi | last post by:
Deal all, The type typedef double ***tmp_tensor3; is meant to represent a three-dimensional array. For some reasons the standard array-of-array-of-array will not work in my case. Can I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.