Thread: [Dev-C++] Dev-c++ and array !
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Sayajin <sa...@fr...> - 2001-08-26 02:11:02
|
Hello everybody ! ! ! Very strange : Dev-c++ accept the declaration "int Tab[10,10];" (it's not permitted = Visual C++ and Borland C++ don't accpet it) but finally Dev-c++ ignore = the first value so if we declare :=20 - "int Tab[10,2];" for Dev-c++ it means : "int Tab[2];"=20 Strange isnt'it ?=20 |
|
From: Luigi S. <gi...@li...> - 2001-08-26 05:58:49
|
Hi!
My opinion about the issue:
- Visual and Borland compilers assume that by "int Tab[10, 10]" you are
attempting to declare a matrix 10x10, so they warn you that the correct way
to do so is "int Tab[10][10]"
- Dev-C++ (or better yet mingw) compiler assumes that you "know what you
are doing", here is why: in C (and as far as I know this is true in C++)
the following line (assume x is an int)
x = 1, printf("x = %d", x);
means "assign 1 to x and then print it".
In the same fashion, the "int Tab[10, 2]" means: do "something with 10"
(actually nothing) and allocate memory (in static sense) for an array of 2
integers.
At 04.14 26/08/01 +0200, you wrote:
>Hello everybody ! ! !
>
>Very strange :
>Dev-c++ accept the declaration "int Tab[10,10];" (it's not permitted
>Visual C++ and Borland C++ don't accpet it) but finally Dev-c++ ignore
>the first value so if we declare :
>
>- "int Tab[10,2];" for Dev-c++ it means : "int Tab[2];"
>
>Strange isnt'it ?
--
gisan
gi...@li...
|
|
From: Sayajin <sa...@fr...> - 2001-08-26 12:59:46
|
> In the same fashion, the "int Tab[10, 2]" means: do "something with 10" > (actually nothing) and allocate memory (in static sense) for an array of 2 > integers. Do something with 10 ? Doing what ? |
|
From: Luigi S. <gi...@li...> - 2001-08-28 03:31:33
|
Hi!
Sorry, my answer was a little confusing, I wrote it after compiling this
small example:
test.c
------
/*********************************************************************
test things like: int tab[10, 2]
*********************************************************************/
#include <stdio.h>
void
print_arr(const int *, int);
/********************************************************************/
int
main()
{
int x;
int tab[10, 2];
x = 1, printf("x = %d\n", x);
tab[0] = 1;
tab[1] = 10;
print_arr(tab, 2);
return 0;
}
/********************************************************************/
void
print_arr(const int *arr, int n)
{
int i;
for(i = 0; i < n; i++)
printf("arr[%d] = %d\n", i, arr[i]);
}
---
When you compile it you should see the message:
test.c:17: warning left-hand operand of comma has no effect
So "do something with 10 (actually nothing)" was my pesonal translation
of the above warning message. :-)
At 15.03 26/08/01 +0200, you wrote:
> > In the same fashion, the "int Tab[10, 2]" means: do "something with 10"
> > (actually nothing) and allocate memory (in static sense) for an array of 2
> > integers.
>
>Do something with 10 ? Doing what ?
>
>
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--
gisan
gi...@li...
|
|
From: Ioannis V. <no...@ya...> - 2001-08-26 08:36:57
|
You are a hacker... :) =20 =20 Ioannis =20 * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com <http://www.noicys.f2s.com/>=20 * Alternative URL: http://run.to/noicys -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Sayajin Sent: Sunday, August 26, 2001 4:15 AM To: dev...@li... Subject: [Dev-C++] Dev-c++ and array ! Hello everybody ! ! ! =20 Very strange : Dev-c++ accept the declaration "int Tab[10,10];" (it's not permitted Visual C++ and Borland C++ don't accpet it) but finally Dev-c++ ignore the first value so if we declare :=20 - "int Tab[10,2];" for Dev-c++ it means : "int Tab[2];"=20 Strange isnt'it ?=20 |
|
From: Sayajin <sa...@fr...> - 2001-08-26 12:57:29
|
Messagean Hacker ? Why ? ----- Original Message -----=20 From: Ioannis Vranos=20 To: dev...@li...=20 Sent: Sunday, August 26, 2001 11:36 AM Subject: RE: [Dev-C++] Dev-c++ and array ! You are a hacker... :) Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys -----Original Message----- From: dev...@li... = [mailto:dev...@li...] On Behalf Of Sayajin Sent: Sunday, August 26, 2001 4:15 AM To: dev...@li... Subject: [Dev-C++] Dev-c++ and array ! Hello everybody ! ! ! Very strange : Dev-c++ accept the declaration "int Tab[10,10];" (it's not permitted = Visual C++ and Borland C++ don't accpet it) but finally Dev-c++ ignore = the first value so if we declare :=20 - "int Tab[10,2];" for Dev-c++ it means : "int Tab[2];"=20 Strange isnt'it ?=20 |
|
From: Vassili <v.v...@bt...> - 2001-08-27 13:04:47
|
Here is a snip from the wrox press tutorial, it might help explain a few =
things:
Try It Out - The Comma Operator
The comma operator allows you to specify several expressions where =
normally only one might occur. This is best understood by looking at an =
example of how it is used:
// EX1_05.CPP
// Exercising the comma operator
#include <iostream>
using namespace std;
int main()
{
long num1 =3D 0, num2 =3D 0, num3 =3D 0, num4 =3D 0;
num4 =3D (num1 =3D 10, num2 =3D 20, num3 =3D 30);
cout << endl
<< "The value of a series of expressions "
<< "is the value of the right most: "
<< num4;
cout << endl;
return 0;
}
How It Works
If you compile and run this program you will get this output:
The value of a series of expressions is the value of the right most: 30
This is fairly self-explanatory. The variable num4 receives the value of =
the last of the series of three assignments, the value of an assignment =
being the value assigned to the left-hand side. The parentheses in the =
assignment for num4 are essential. You could try executing this without =
them to see the effect. Without the parentheses, the first expression =
separated by commas in the series will become:
num4 =3D num1 =3D 10
So, num4 will have the value 10.
Of course, the expressions separated by the comma operator don't have to =
be assignments. We could equally well write the following:
long num1 =3D 1, num2 =3D 10, num3 =3D 100, num4 =3D 0;
num4 =3D (++num1, ++num2, ++num3);
The effect of this assignment would be to increment the variables num1, =
num2 and num3 by 1, and to set num4 to the value of the last expression =
which will be 101.=20
This example is aimed at illustrating the effect of the comma operator, =
and is not an example of how to write good code. As you can see, writing =
an assignment statement in this fashion can be very misleading.
----- Original Message -----=20
From: Sayajin=20
To: dev...@li...=20
Sent: Sunday, August 26, 2001 3:14 AM
Subject: [Dev-C++] Dev-c++ and array !
Hello everybody ! ! !
Very strange :
Dev-c++ accept the declaration "int Tab[10,10];" (it's not permitted =
Visual C++ and Borland C++ don't accpet it) but finally Dev-c++ ignore =
the first value so if we declare :=20
- "int Tab[10,2];" for Dev-c++ it means : "int Tab[2];"=20
Strange isnt'it ?=20
|
|
From: Elias P. <eli...@ao...> - 2001-08-27 13:24:08
|
> Hello everybody ! ! ! > > Very strange : > Dev-c++ accept the declaration "int Tab[10,10];" (it's not permitted Visual > C++ and Borland C++ don't accpet it) but finally Dev-c++ ignore the first > value so if we declare : > > - "int Tab[10,2];" for Dev-c++ it means : "int Tab[2];" > > Strange isnt'it ? It's always a good idea to turn on warnings, I believe you can do that somewhere in the menu of dev-c++. Else for gcc it is the -Wall option. -- Elias Pschernig |