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: -
#define size 2
-
#define size2 size*size
-
#define point2 (size+1)*(size+1)
-
int main ( )
-
{
-
float ax[size2][24],ay[size2][24];
-
float R[size2][point2],S[size2][24][point2];
-
float e;
-
for (i=0; i<size2; i++){
-
for (l=0;l<24;l++){
-
for (j = 0; i < Lx[i]; j++){
-
for (k = 0; k < Ly[i]; k++){
-
e=j+k*Lx[i];
-
R[i][l][e]=ax[i][l];
-
S[i][l][e]=ay[i][l];
-
}
-
}
-
}
-
}
-
}
-
I don't know what's wrong..
if you could help me, I really appreciate it
Thank you
9 4289
What is Lx? It's not in your snippet.
Sorry...
I cut my code because it is so long...
Here my complete code (although I cut a few part) -
#include <stdlib.h>
-
#include <math.h>
-
#include <stdio.h>
-
#include <conio.h>
-
-
#define size 2
-
#define size2 size*size
-
#define point1 (size+1)
-
#define point2 (size+1)*(size+1)
-
#define rotation 45
-
#define deg rotation*3.14159265/180
-
-
int main()
-
{
-
float xr[point2], yr[point2];
-
float xb[point2], yb[point2];
-
float bx[size2][4],by[size2][4];
-
float bx_max[size2],bx_min[size2],by_max[size2],by_min[size2];
-
float Lx1[size],Lx2[size],Ly1[size],Ly2[size];
-
float Lx[size],Ly[size];
-
float R[size2][point2],S[size2][24][point2];
-
int i,j,k,l,flag1,flag2;
-
int a,d;
-
-
for (i = 0; i < point1; i++){
-
for (j = 0; j < point1; j++){
-
xr[j+i*point1] = -(size/2) + j;
-
yr[j+i*point1] = (size/2) - i;
-
}
-
}
-
for (i = 0; i < point2; i++){
-
xb[i] = xr[i]*cos(deg) - yr[i]*sin(deg);
-
yb[i] = xr[i]*sin(deg) + yr[i]*cos(deg);
-
}
-
for (i = 0; i < size; i++){
-
for (j = 0; j < size; j++){
-
a=j+i*size;
-
by[a][0]=xr[a+i]*sin(deg) + yr[a+i]*cos(deg);
-
by[a][1]=xr[a+1+i]*sin(deg) + yr[a+1+i]*cos(deg);
-
by[a][2]=xr[a+i+point1]*sin(deg) + yr[a+i+point1]*cos(deg);
-
by[a][3]=xr[a+i+1+point1]*sin(deg) + yr[a+i+1+point1]*cos(deg);
-
bx[j+i*size][0]=xb[j+i*size+i];
-
bx[j+i*size][1]=xb[a+i+1];
-
bx[j+i*size][2]=xb[a+i+point1];
-
bx[j+i*size][3]=xb[1+i+a+point1];
-
}
-
}
-
for (i=0; i<size2; i++){
-
for (j = 0; j < 4; j++){
-
bx_max[i]=bx[i][0];
-
if (bx[i][j]>bx_max[i]){
-
bx_max[i]=bx[i][j];
-
}
-
by_max[i]=by[i][1];
-
if (by[i][j]>by_max[i]){
-
by_max[i]=by[i][j];
-
}
-
}
-
}
-
for (i=0; i<size2; i++){
-
for (j = 0; j < 4; j++){
-
bx_min[i]=bx[i][0];
-
if (bx[i][j]<bx_min[i]){
-
bx_min[i]=bx[i][j];
-
}
-
// by_min[i]=by[i][0];
-
if (by[i][j]<by_min[i]){
-
by_min[i]=by[i][j];
-
}
-
}
-
}
-
for (i=0; i<size2; i++){
-
Lx1[i]=ceil (bx_max[i]);
-
Lx2[i]=floor (bx_min[i]);
-
Ly1[i]=ceil (by_max[i]);
-
Ly2[i]=floor(by_min[i]);
-
Lx[i]=Lx1[i]-Lx2[i];
-
Ly[i]=Ly1[i]-Ly2[i];
-
}
-
for (i=0; i<size2; i++){
-
for (l=0;l<24;l++){
-
for (j = 0; i < Lx[i]; j++){
-
for (k = 0; k < Ly[i]; k++){
-
e=j+k*Lx[i];
-
R[i][l][e]=ax[i][l];
-
S[i][l][e]=ay[i][l];
-
}
-
}
-
}
-
}
-
-
}
-
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
declaration: float R[size2][point2]
usage: R[i][l][e]
Decalration contains 2 indexes, and you try to index it with 3 indexes.
@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?
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.
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.
@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
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.
@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
Sign in to post your reply or Sign up for a free account.
Similar topics
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:...
|
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...
|
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).
...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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: 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,...
|
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...
|
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,...
|
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...
|
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,...
| |