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

Help please

float (*ptr)[31][13][256][256], *p;

main()

{
float ****A = NULL;
int cnt, cnt1, cnt2, cnt3;

A = malloc(31* sizeof *A);

for(cnt = 0; cnt < 31; ++cnt) {
A[cnt] = malloc(130* sizeof **A);
}

for(cnt = 0; cnt < 31; ++cnt) {
for(cnt1 = 0; cnt1 < 130; ++cnt1) {
A[cnt][cnt1] = malloc(256 * sizeof ***A) ;
}
}

for(cnt = 0; cnt < 3; ++cnt) {
for(cnt1 = 0; cnt1 < 130; ++cnt1) {
for(cnt2 = 0; cnt2 < 256; ++cnt2) {
A[cnt][cnt1][cnt2] = malloc(256 * sizeof ****A);
}
}
}

ptr=&A[0];

}

when i do this its gives me assignment from incompatible pointer type
for the statement"ptr=&A[0]".If i replace array [A] with a static array
like say A [31][130][256][256]
i dont get any warning messages.Why am i egtting an error when iam
assigning the pointer tto the dynamic array?

Thanks

Jul 3 '06 #1
3 1152
vinod.bhavn...@gmail.com wrote:
float (*ptr)[31][13][256][256], *p;
.... snip ...

Multidimensional arrays are a common newbie problem, so it is a FAQ.
See:
<http://c-faq.com/>

Specifically:
<http://c-faq.com/aryptr/dynmuldimary.html>

Jul 3 '06 #2
vi************@gmail.com wrote:
float (*ptr)[31][13][256][256], *p;

main()

{
float ****A = NULL;
int cnt, cnt1, cnt2, cnt3;

A = malloc(31* sizeof *A);

for(cnt = 0; cnt < 31; ++cnt) {
A[cnt] = malloc(130* sizeof **A);
}

for(cnt = 0; cnt < 31; ++cnt) {
for(cnt1 = 0; cnt1 < 130; ++cnt1) {
A[cnt][cnt1] = malloc(256 * sizeof ***A) ;
}
}

for(cnt = 0; cnt < 3; ++cnt) {
for(cnt1 = 0; cnt1 < 130; ++cnt1) {
for(cnt2 = 0; cnt2 < 256; ++cnt2) {
A[cnt][cnt1][cnt2] = malloc(256 * sizeof ****A);
}
}
}

ptr=&A[0];

}

when i do this its gives me assignment from incompatible pointer type
for the statement"ptr=&A[0]".If i replace array [A] with a static array
like say A [31][130][256][256]
i dont get any warning messages.Why am i egtting an error when iam
assigning the pointer tto the dynamic array?

Thanks
Well, this might sound a bit obvious, but there is indeed a type
mismatch here and that is why the compiler is giving you an error.
Before you call me crazy, let me explain. MOST OF THE TIME, you can use
pointers and arrays interchangeably. For instance, char * string and
char string[] can USUALLY be used interchangeably. If a function
expects an array of char, you can give it a char * and vise-versa.

*JUST WHAT IS A?*
When you defined A, you told the compiler that it is a pointer to a
pointer to a pointer to a pointer to a float. That means, when you try
and access the float, the computer will look in the address named by A
and expect to see a pointer(a memory address). When the computer jumps
to the address in that pointer it needs to know what type of data is
there. You told the compiler that the data to expect is yet another
pointer(memory address) and the computer will follow that. This will be
repeated three more times, at which time the computer expects to
finally find the float.

*ISN'T THAT WHAT ptr IS?*
No. ptr is a pointer to a four dimensional array of floats. That means,
when you use indirection to access data through ptr, the computer will
look in the memory address that is named by ptr. The computer expects
to see a pointer(memory address) which it will. So far, this is the
same kind of thing that A is. Now once the computer jumps over to the
address that is pointed to by ptr, the computer expects to see a bunch
of adjacent floats!!! Not another pointer!!!! That is what is different
about these two variables. This stuff is tricky, so watch out.

I recommend that you read a good book that discusses this subject at
length, such as Expert C Programming by Peter Van Der Linden.

P.S. There might be other errors in your code fragment here, be careful
how you are using sizeof!! I don't think it will return what you think!

Jul 3 '06 #3
backasswards <ba**********@gmail.comwrote:
*JUST WHAT IS A?*
A is A, saith Ayn Rand.
I recommend that you read a good book that discusses this subject at
length, such as Expert C Programming by Peter Van Der Linden.
It seems to be a good text, but OP seems more likely to benefit from
K&R and the FAQ in the short term.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 6 '06 #4

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

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
1
by: the_proud_family | last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com I can't get the ball to go up right side and then I need it to turn around and keep turning until velocity=0 I have been at it for the ...
0
by: Kurt Watson | last post by:
Iím having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
12
by: Christo | last post by:
borland c++ 5.01 character constant must be one or two characters long get this when compiling my first c++ program can anyone out there help? it is highlighting this line as the problem ...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
17
by: JT | last post by:
Help me the following C++ question: Write a program to help a local bookshop automate its billing system. The program should do the following: (a)Let the user enter the ISBN, the system will...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
2
by: =?Utf-8?B?U2NvdHRSYWREZXY=?= | last post by:
I'm creating a doc project for my c# program. I've done this before but this time sonething is wrong. I build my doc project and is succeeds but when I open the help file, there is no documentation...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.