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

Array subscription

16
Hi....

I have a problem with my declaring my array. I just keep getting message like this:
invalid types `float[9][float]' for array subscript

Here my code:
Expand|Select|Wrap|Line Numbers
  1. #define size 2
  2. #define size2 size*size
  3. #define point2 (size+1)*(size+1)
  4. int main ( )
  5. {
  6. float ax[size2][24],ay[size2][24]; 
  7. float R[size2][point2],S[size2][24][point2]; 
  8. float e;
  9. for (i=0; i<size2; i++){
  10.      for (l=0;l<24;l++){
  11.           for (j = 0; i < Lx[i]; j++){
  12.         for (k = 0; k < Ly[i]; k++){
  13.                     e=j+k*Lx[i];
  14.                      R[i][l][e]=ax[i][l];
  15.                       S[i][l][e]=ay[i][l];
  16.                     }
  17.               }
  18.         }
  19. }
  20. }
  21.  
I don't know what's wrong..
if you could help me, I really appreciate it

Thank you
Apr 4 '09 #1
9 4289
weaknessforcats
9,208 Expert Mod 8TB
What is Lx? It's not in your snippet.
Apr 4 '09 #2
mingke
16
Sorry...
I cut my code because it is so long...
Here my complete code (although I cut a few part)
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. #define size 2
  7. #define size2 size*size
  8. #define point1 (size+1)
  9. #define point2 (size+1)*(size+1)
  10. #define rotation 45
  11. #define deg rotation*3.14159265/180
  12.  
  13. int main()
  14. {
  15. float xr[point2], yr[point2];
  16. float xb[point2], yb[point2];
  17. float bx[size2][4],by[size2][4];  
  18. float bx_max[size2],bx_min[size2],by_max[size2],by_min[size2];        
  19. float Lx1[size],Lx2[size],Ly1[size],Ly2[size];  
  20. float Lx[size],Ly[size]; 
  21. float R[size2][point2],S[size2][24][point2]; 
  22. int i,j,k,l,flag1,flag2;
  23. int a,d;
  24.  
  25.     for (i = 0; i < point1; i++){
  26.         for (j = 0; j < point1; j++){
  27.            xr[j+i*point1] = -(size/2) + j;
  28.            yr[j+i*point1] = (size/2) - i;
  29.           }
  30.     }
  31.     for (i = 0; i < point2; i++){
  32.          xb[i] = xr[i]*cos(deg) - yr[i]*sin(deg);
  33.            yb[i] = xr[i]*sin(deg) + yr[i]*cos(deg);
  34.     }
  35. for (i = 0; i < size; i++){
  36.   for (j = 0; j < size; j++){            
  37.      a=j+i*size;
  38.      by[a][0]=xr[a+i]*sin(deg) + yr[a+i]*cos(deg);    
  39.      by[a][1]=xr[a+1+i]*sin(deg) + yr[a+1+i]*cos(deg);   
  40.      by[a][2]=xr[a+i+point1]*sin(deg) + yr[a+i+point1]*cos(deg);
  41.      by[a][3]=xr[a+i+1+point1]*sin(deg) + yr[a+i+1+point1]*cos(deg);
  42.      bx[j+i*size][0]=xb[j+i*size+i];
  43.      bx[j+i*size][1]=xb[a+i+1]; 
  44.      bx[j+i*size][2]=xb[a+i+point1];                       
  45.      bx[j+i*size][3]=xb[1+i+a+point1];
  46.    }
  47. }
  48. for (i=0; i<size2; i++){
  49.           for (j = 0; j < 4; j++){
  50.             bx_max[i]=bx[i][0];
  51.                 if (bx[i][j]>bx_max[i]){
  52.                     bx_max[i]=bx[i][j];
  53.                 }
  54.             by_max[i]=by[i][1];
  55.                 if (by[i][j]>by_max[i]){
  56.                     by_max[i]=by[i][j];
  57.                 }
  58.        }
  59.   }               
  60.    for (i=0; i<size2; i++){
  61.           for (j = 0; j < 4; j++){
  62.             bx_min[i]=bx[i][0];
  63.             if (bx[i][j]<bx_min[i]){
  64.                 bx_min[i]=bx[i][j];
  65.             }
  66.            // by_min[i]=by[i][0];  
  67.             if (by[i][j]<by_min[i]){
  68.                 by_min[i]=by[i][j];
  69.             }
  70.        }
  71.    }
  72. for (i=0; i<size2; i++){
  73.        Lx1[i]=ceil (bx_max[i]);
  74.        Lx2[i]=floor (bx_min[i]);
  75.        Ly1[i]=ceil (by_max[i]);
  76.        Ly2[i]=floor(by_min[i]);
  77.        Lx[i]=Lx1[i]-Lx2[i];
  78.        Ly[i]=Ly1[i]-Ly2[i];
  79.   }
  80. for (i=0; i<size2; i++){
  81.       for (l=0;l<24;l++){
  82.         for (j = 0; i < Lx[i]; j++){
  83.           for (k = 0; k < Ly[i]; k++){
  84.                e=j+k*Lx[i];
  85.                R[i][l][e]=ax[i][l];
  86.                S[i][l][e]=ay[i][l];
  87.            }
  88.        }
  89.     }
  90.  }
  91.  
  92. }
  93.  
while ax and ay are values that have been stated before. I'm sorry I didn't put it in my code because it's so long.
And the my problem is it's said that I have invalid types `float[9][float]' for array subscript (R[i][l][e] and S[i][l][e])


Thank you
Apr 4 '09 #3
newb16
687 512MB
declaration: float R[size2][point2]
usage: R[i][l][e]
Decalration contains 2 indexes, and you try to index it with 3 indexes.
Apr 4 '09 #4
mingke
16
@newb16

thanks for your respond....

But how about S[i][l][e]?
I declared it with three index and use it with three index too....
Same things happen if I declared R with three index...

Is it possible because e contains Lx[i] and somehow I declared it wrong?
Apr 5 '09 #5
newb16
687 512MB
Maybe you can't use float as array index, but only integral type. I tried to compile the code you posted, but got an 'e was not declared in this scope' error at line 84.
Apr 5 '09 #6
weaknessforcats
9,208 Expert Mod 8TB
Why are floats being used at all?

I have always recommended that unless you can write down on paper the precise technical reason you need a float you should double instead.

You lose accuracy converting from double to float.

Next, array indexes are integers. When you use a float or a double to calculate an index, all of the integers are converted to double and the calculation is done as a double. Then since array indexes are integers, the resultant double is converted to an int by chopping off the decimals and since a double can hold a bigger value than an int, maybe some of the lower digits are chopped off as well.

You cannot convert a double to an int.

Before I can go further, I would need code that compiles without warnings.
Apr 5 '09 #7
JosAH
11,448 Expert 8TB
@weaknessforcats
It's more dramatic than that: if you use floats or doubles for an index expression the code violates a 'shall clause'. This is what the C Standard says:

3.3.2.1 Array subscripting

Constraints

One of the expressions shall have type "pointer to object type ,''
the other expression shall have integral type, and the result has type
"type .''
Violating a shall clause is a crime: error messages must be given and the author of the violation must be defenestrated. This is what the C Standard says about those 'shall clauses':

In this Standard, "shall'' is to be interpreted as a requirement
on an implementation or on a program; conversely, "shall not'' is to
be interpreted as a prohibition.
kind regards,

Jos
Apr 5 '09 #8
donbock
2,426 Expert 2GB
It can be more surprising than you expect to invoke "undefined behavior" or "implementation-defined behavior" in your C program.

I don't know if this is just an urban legend, but the word is that the implementation-defined reaction of early versions of gcc was to launch a unix game such as NetHack or Rogue whenever you compiled a program containing #pragma.

The only difference between "undefined behavior" and "implementation-defined behavior" is that the compiler has to document what happens in the latter case. Other than that, anything goes. It would be legal from a C Standard point-of-view to reformat your hard drive.

Defenestration is restrained behavior.
Apr 6 '09 #9
JosAH
11,448 Expert 8TB
@donbock
It is true, I saw the sources: when the cppp saw a #pragma it fired up a game. (I forgot which one). It was a single file mess of a program; later versions of the preprocessor have cleaned up a lot.

kind regards,

Jos
Apr 6 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ernesto | last post by:
Using the "Pull New Subscription" wizrd in the enterprise manager, I can create a subscription without a problem. Howwever using TSQL I cannot do the same thing: Using this sequence:...
11
by: DraguVaso | last post by:
Hi, I want to download Visual Studio 2005 Beta 1 Refresh, but on the site of Microsoft they say it is only for MSDN subscribers? what is a MSDN subscriber and how do I get it? When I try to...
3
by: Max A. Bündchen | last post by:
My enterprise is a Registered Microsoft Partner and we would to acquire a MSDN Universal subscription under the Empower ISV Program to start a new project in .Net (today we dev under VFP 7). ...
5
by: Odd Bjørn Andersen | last post by:
I have a problem when using Replication Center on version 8.2 (fixpack 9) when I try to manage my SQL Replication environment. When I add existing Apply Control Servers I am not able to see...
19
by: Geetesh | last post by:
Recently i saw a code in which there was a structer defination similar as bellow: struct foo { int dummy1; int dummy2; int last }; In application the above array is always allocated at...
3
by: Alex K. | last post by:
Hi all I have a class MyClass that exposes event A. Inside the class, I need to catch the moment when some other class subscribes to the event A. In other words, when some other class executes...
6
by: WebMatrix | last post by:
Hello, Sorry for the repost, I haven’t got any response in aspnet.webservices group. We have a web service being used by several clients. It's SSL secured, uses Windows (Basic)...
12
by: Sheldon | last post by:
Hi, I have two arrays that are of the same dimension but having 3 different values: 255, 1 or 2. I would like to set all the positions in both arrays having 255 to be equal, i.e., where one...
2
by: =?Utf-8?B?SmFzb24gQS4gSmVuc2Vu?= | last post by:
I have a MSDN Subscription expiring this month but really need Visual Studio 2008 when it comes out. I called customer service to find out but they don't know. They seemed to think it was a...
7
by: John | last post by:
Hi Can I have an array of type OleDb.OleDbConnection that has strings as subscription values? The reason I need this is my app reads a configuration file with db names and their locations and it...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.