dev-cpp-users Mailing List for Dev-C++ (Page 376)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(115) |
Nov
(154) |
Dec
(258) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(377) |
Feb
(260) |
Mar
(249) |
Apr
(188) |
May
(152) |
Jun
(150) |
Jul
(195) |
Aug
(202) |
Sep
(200) |
Oct
(286) |
Nov
(242) |
Dec
(165) |
| 2002 |
Jan
(245) |
Feb
(241) |
Mar
(239) |
Apr
(346) |
May
(406) |
Jun
(369) |
Jul
(418) |
Aug
(357) |
Sep
(362) |
Oct
(597) |
Nov
(455) |
Dec
(344) |
| 2003 |
Jan
(446) |
Feb
(397) |
Mar
(515) |
Apr
(524) |
May
(377) |
Jun
(387) |
Jul
(532) |
Aug
(364) |
Sep
(294) |
Oct
(352) |
Nov
(295) |
Dec
(327) |
| 2004 |
Jan
(416) |
Feb
(318) |
Mar
(324) |
Apr
(249) |
May
(259) |
Jun
(218) |
Jul
(212) |
Aug
(259) |
Sep
(158) |
Oct
(162) |
Nov
(214) |
Dec
(169) |
| 2005 |
Jan
(111) |
Feb
(165) |
Mar
(199) |
Apr
(147) |
May
(131) |
Jun
(163) |
Jul
(235) |
Aug
(136) |
Sep
(84) |
Oct
(88) |
Nov
(113) |
Dec
(100) |
| 2006 |
Jan
(85) |
Feb
(119) |
Mar
(33) |
Apr
(31) |
May
(56) |
Jun
(68) |
Jul
(18) |
Aug
(62) |
Sep
(33) |
Oct
(55) |
Nov
(19) |
Dec
(40) |
| 2007 |
Jan
(22) |
Feb
(49) |
Mar
(34) |
Apr
(51) |
May
(66) |
Jun
(43) |
Jul
(116) |
Aug
(57) |
Sep
(70) |
Oct
(69) |
Nov
(97) |
Dec
(86) |
| 2008 |
Jan
(32) |
Feb
(47) |
Mar
(106) |
Apr
(67) |
May
(28) |
Jun
(39) |
Jul
(31) |
Aug
(25) |
Sep
(18) |
Oct
(25) |
Nov
(5) |
Dec
(21) |
| 2009 |
Jan
(33) |
Feb
(27) |
Mar
(27) |
Apr
(22) |
May
(22) |
Jun
(10) |
Jul
(17) |
Aug
(9) |
Sep
(21) |
Oct
(13) |
Nov
(4) |
Dec
(11) |
| 2010 |
Jan
(10) |
Feb
(8) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(26) |
Nov
(9) |
Dec
(1) |
| 2011 |
Jan
(21) |
Feb
(16) |
Mar
(4) |
Apr
(19) |
May
(26) |
Jun
(9) |
Jul
(6) |
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(2) |
Dec
(1) |
| 2012 |
Jan
(4) |
Feb
(7) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(10) |
Jul
(1) |
Aug
(1) |
Sep
(18) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
| 2013 |
Jan
(4) |
Feb
(2) |
Mar
(15) |
Apr
(6) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(9) |
Dec
|
| 2014 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(4) |
| 2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(9) |
Nov
(35) |
Dec
(6) |
| 2016 |
Jan
(7) |
Feb
(10) |
Mar
(10) |
Apr
(9) |
May
(13) |
Jun
(9) |
Jul
(1) |
Aug
(3) |
Sep
(3) |
Oct
(1) |
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Per W. <pw...@ia...> - 2003-05-30 07:43:59
|
Try
char list_ch[][2] = {{'1','a'},{'2','b'},...};
/Per W
On Fri, 30 May 2003, Christian Schmidt wrote:
> char list_ch[][2] = {'1','a','2','b','3','c','4','d','5','e','6','f'};
>
> 18 [Warning] missing braces around initializer
>
> Chris
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: eBay
> Get office equipment for less on eBay!
> http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: <or...@vp...> - 2003-05-30 07:13:38
|
Christian Schmidt wrote:
> char list_ch[][2] = {'1','a','2','b','3','c','4','d','5','e','6','f'};
This is a 2-dimensional array. Are you sure you wanted this?
Try:
char list_ch[] = {'1','a','2','b','3','c','4','d','5','e','6','f'};
--
Greetings,
Balázs
|
|
From: Ioannis V. <iv...@te...> - 2003-05-30 03:36:08
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Per Westermark > Sent: Friday, May 30, 2003 4:23 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > inicializations > > > Yes, we agree that 'const int x = <value>' is efficient. > We don't agree that 'const int &x = <value>' is efficient. The reference can't be used to provide the size of a built in array, so my mistake for that. On the other hand regarding reference, a compiler would be able to optimise out and make it occupy no more space. const int &x=7; Can you tell me why that wouldn't be able to be equivalent to #define x 7 when used just as a value and not accessed in any other way? As I can think of it, a const reference should be more eaiser to optimise out than a const variable. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Christian S. <sm...@xs...> - 2003-05-30 01:10:54
|
char list_ch[][2] = {'1','a','2','b','3','c','4','d','5','e','6','f'};
18 [Warning] missing braces around initializer
Chris
|
|
From: Smurf, P. <smu...@xs...> - 2003-05-30 00:30:51
|
I check amazon.com for the reviews and hopefully expertz of the book. And will then base my decision on that. -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of David McKen Sent: vrijdag 30 mei 2003 2:11 To: dev...@li... Subject: [Dev-C++] RPG Game A.I. book suggestion Does anyone have any suggestions for a good book on game A.I. I would like one that deals with the aspects dealt with RPG-type games. I need to control the Non-Player Characters in the game I am writing. Thanks. __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com ------------------------------------------------------- This SF.net email is sponsored by: eBay Get office equipment for less on eBay! http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
|
From: David M. <ci...@ya...> - 2003-05-30 00:11:25
|
Does anyone have any suggestions for a good book on game A.I. I would like one that deals with the aspects dealt with RPG-type games. I need to control the Non-Player Characters in the game I am writing. Thanks. __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com |
|
From: Per W. <pw...@ia...> - 2003-05-29 22:03:00
|
I was also talking about c++, so obviously the extension of the source file (I normally use *.cc) tells gcc to use g++ for c++ compilation. /Per W On Thu, 29 May 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Friday, May 30, 2003 2:00 AM > > To: Ioannis Vranos > > Cc: Dev-C++ Mailing List > > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > > inicializations > > > > > > I guess you don't think of gcc as a decent compiler then. > > > > try gcc -O3 -S on the code below and look at the output. > > 4 byte for the value 7 > > 4 byte for the SIZE reference. > > access loads SIZE and pushes [SIZE] (4 byte addr info + extra instr) > > > > with const int SIZE = 7 > > zero byte for value > > every access pushes 7 directly. (4 byte value) > > > > Most compilers treat 'const int v = <value>' identical to #define XX > > <value>, i.e. optimal code is generated. > > > > ... and we are talking about C++ here, so g++ is the compiler and not gcc. > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL 1: http://run.to/noicys > * Alternative URL 2: http://www.noicys.cjb.net > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: <Avi...@ne...> - 2003-05-29 21:50:51
|
Typo I meant 32 bits :-)
Per Westermark <pw...@ia...> wrote:
>You are using mighty big integers :-)
>
>A 32-byte unsigned integer would store numbers up to 1*10^77
>
>/Per W
>
>On Thu, 29 May 2003, Avik Ghose wrote:
>
>> Hi Andre,
>> you are right, there's probably no third way out. Now I prefer to use the first one due to two reasons.
>> 1> Being textual subsitution, the #define macro does not use up memory size whereas an integer uses up 32 bytes, though that is negligent for most purposes.
>> 2> The more important being that apart from compiler systems that support C++ along with C, the interpretation of const by the compilers around is a bit non-standard. Like in the Cygwin gcc complier assigment to const variables result only in a warning at compile time and program runs fine, and prints out 20!!!.
>> #include <stdio.h>
>> int main()
>> {
>> const int i = 10;
>> i=20;
>> printf("%d\n",i);
>> return 0;
>> }/*main*/
>> So well although I cannot remember of a third way to do it right now, obviously the first approach is better.
>>
>>
>>
>>
>> André_Macário_Barros <and...@su...> wrote:
>> Dear Users,
>>
>> For the sake of flexibility, I think we only have two ways to iniciatize
>> a
>> size of an array:
>> 1) via #define:
>> #define MAX 10
>> ...
>> int vect[MAX];
>> ...
>>
>> 2) via cont variable:
>> const int size=10;
>> ...
>> int vetc[size];
>> ...
>>
>> So, in both ways, everytime if I need to change the size of the arrays, it´s
>> only necessary to change 10 to the other value.
>>
>> -->My questions:
>> 1) Is there more ways to to this?
>> 2) For theese two ways presented here, when use one and when use the other?
>> Explaining a little more what I need to know: in a "good programming
>> technique"
>> point of view, what of theese two is the preferred of the programmers
>> (please
>> don´t answer "pointers" ...lol).
>>
>> Regards
>> André
>>
>>
>>
>>
>> -------------------------------------------------------
>> This SF.net email is sponsored by: eBay
>> Get office equipment for less on eBay!
>> http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
>> _______________________________________________
>> Dev-cpp-users mailing list
>> Dev...@li...
>> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>>
>>
>> Thanx and Regards
>> Avik Ghose
>> Catch all the cricket action. Download Yahoo! Score tracker
>
>
--
Regards
---------------------------------------
Avik Ghose
Software Engineer (Real Time Group)
Rebaca
Systron Building, 3rd Floor
Plot No: J-5, Block: EP & GP
Saltlake Electronics Complex, Sector V
Kolkata: 700091
India
Phone: 91-33-2357-7177 ext 16
Fax: 91-33-2357-7178
Mobile: 91-0-9830039737
__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397
Get AOL Instant Messenger 5.1 free of charge. Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455
|
|
From: Per W. <pw...@ia...> - 2003-05-29 21:30:50
|
For comparing size of code - either go for the map file, or look at the assembler output. The exe file size isn't interesting. A look at the assembler output also shows the difference between fast, slow, big, small, ... code. Extra memory references are almost always bad. Extra bytes of code might not be expensive, as long as the processor have bandwidth enough - for example in a loop small enough to fit in the L1 cache, the processor doesn't consume any code bandwidth after the first iteration. In such a case, a larger code block might actually be faster by removing an extra access to a memory location. /Per W On Thu, 29 May 2003, OROSZI Bal=E1zs wrote: > Ioannis Vranos wrote: > > 29/05/2003 11:09 ?? 23.036 temp.exe > > ... > > 29/05/2003 11:10 ?? 23.036 temp.exe > > > > So the compiler optimises out the const int thing. > > Are you sure if size is the same, exe is same? Look at the contents of > it with a comparison program. gcc works in blocks or what, so 2 totally > different programs might have the same size. > > -- > Greetings, > Bal=E1zs > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Per W. <pw...@ia...> - 2003-05-29 21:24:28
|
Yes, we agree that 'const int x = <value>' is efficient. We don't agree that 'const int &x = <value>' is efficient. /Per W On Thu, 29 May 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Friday, May 30, 2003 2:00 AM > > To: Ioannis Vranos > > Cc: Dev-C++ Mailing List > > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > > inicializations > > > > Most compilers treat 'const int v = <value>' identical to #define XX > > <value>, i.e. optimal code is generated. > > > ... and what do you mean by that? It seems we agree? > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL 1: http://run.to/noicys > * Alternative URL 2: http://www.noicys.cjb.net > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: <or...@vp...> - 2003-05-29 21:10:02
|
Per Westermark wrote: > I guess you don't think of gcc as a decent compiler then. An interesting thing I found, when examining g++ deeply: GCC is so smart, it even optimizes everything possible. Suppose you have a function, that returns a class. The normal behaviour would be: call copy constructor, return copied object. BUT if the variable was a local variable (created in the function) and you return that, then the "theoretical" behaviour would still be: copy object, return copied object, delete local variable, BUT gcc makes it very different: it simply return the local object without any copy, etc. It is not harmful, as the object would have been deleted anyway, so it is truly easier to simply return the local variable one-in-one. It is faster for sure. It truly does this, as I stated - I have checked the pointer for the object, and it is the same in the function, and the after return. Interesting... -- Greetings, Balázs |
|
From: <or...@vp...> - 2003-05-29 21:02:58
|
Ioannis Vranos wrote: > 29/05/2003 11:09 ?? 23.036 temp.exe > ... > 29/05/2003 11:10 ?? 23.036 temp.exe > > So the compiler optimises out the const int thing. Are you sure if size is the same, exe is same? Look at the contents of it with a comparison program. gcc works in blocks or what, so 2 totally different programs might have the same size. -- Greetings, Balázs |
|
From: Ioannis V. <iv...@em...> - 2003-05-29 20:19:30
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Friday, May 30, 2003 2:00 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > inicializations > > Most compilers treat 'const int v = <value>' identical to #define XX > <value>, i.e. optimal code is generated. ... and what do you mean by that? It seems we agree? Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Ioannis V. <iv...@em...> - 2003-05-29 20:15:48
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Friday, May 30, 2003 2:00 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > inicializations > > > I guess you don't think of gcc as a decent compiler then. > > try gcc -O3 -S on the code below and look at the output. > 4 byte for the value 7 > 4 byte for the SIZE reference. > access loads SIZE and pushes [SIZE] (4 byte addr info + extra instr) > > with const int SIZE = 7 > zero byte for value > every access pushes 7 directly. (4 byte value) > > Most compilers treat 'const int v = <value>' identical to #define XX > <value>, i.e. optimal code is generated. ... and we are talking about C++ here, so g++ is the compiler and not gcc. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Ioannis V. <iv...@em...> - 2003-05-29 20:12:39
|
At first the const reference can't be used for the size of the array, my
mistake.
For the rest, I do not get your point:
int main()
{
int array[17];
}
g++ -pedantic-errors -Wall -fexpensive-optimizations -O3 -ffloat-store
-mcpu=pentiumpro temp.cpp -o temp
29/05/2003 11:09 ?? 23.036 temp.exe
For the code:
int main()
{
const int SIZE=17;
int array[SIZE];
}
29/05/2003 11:10 ?? 23.036 temp.exe
So the compiler optimises out the const int thing.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
> -----Original Message-----
> From: Per Westermark [mailto:pw...@ia...]
> Sent: Friday, May 30, 2003 2:00 AM
> To: Ioannis Vranos
> Cc: Dev-C++ Mailing List
> Subject: RE: [Dev-C++] #DEFINE versus cont variables in array
> inicializations
>
>
> I guess you don't think of gcc as a decent compiler then.
>
> try gcc -O3 -S on the code below and look at the output.
> 4 byte for the value 7
> 4 byte for the SIZE reference.
> access loads SIZE and pushes [SIZE] (4 byte addr info + extra instr)
>
> with const int SIZE = 7
> zero byte for value
> every access pushes 7 directly. (4 byte value)
>
> Most compilers treat 'const int v = <value>' identical to #define XX
> <value>, i.e. optimal code is generated.
>
> /Per W
>
> On Thu, 29 May 2003, Ioannis Vranos wrote:
>
> > A third way that guarantees no space occupation by a decent
> compiler is:
> >
> >
> > const int &SIZE = 7;
> >
> >
> >
> >
> >
> >
> > Ioannis Vranos
> >
> > * Programming pages: http://www.noicys.freeurl.com
> > * Alternative URL 1: http://run.to/noicys
> > * Alternative URL 2: http://www.noicys.cjb.net
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: eBay
> > Get office equipment for less on eBay!
> > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
|
|
From: Per W. <pw...@ia...> - 2003-05-29 19:01:38
|
I guess you don't think of gcc as a decent compiler then. try gcc -O3 -S on the code below and look at the output. 4 byte for the value 7 4 byte for the SIZE reference. access loads SIZE and pushes [SIZE] (4 byte addr info + extra instr) with const int SIZE = 7 zero byte for value every access pushes 7 directly. (4 byte value) Most compilers treat 'const int v = <value>' identical to #define XX <value>, i.e. optimal code is generated. /Per W On Thu, 29 May 2003, Ioannis Vranos wrote: > A third way that guarantees no space occupation by a decent compiler is: > > > const int &SIZE = 7; > > > > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL 1: http://run.to/noicys > * Alternative URL 2: http://www.noicys.cjb.net > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Per W. <pw...@ia...> - 2003-05-29 18:43:35
|
You are using mighty big integers :-)
A 32-byte unsigned integer would store numbers up to 1*10^77
/Per W
On Thu, 29 May 2003, Avik Ghose wrote:
> Hi Andre,
> you are right, there's probably no third way out. Now I prefer to use the=
first one due to two reasons.
> 1> Being textual subsitution, the #define macro does not use up memory si=
ze whereas an integer uses up 32 bytes, though that is negligent for most p=
urposes.
> 2> The more important being that apart from compiler systems that support=
C++ along with C, the interpretation of const by the compilers around is a=
bit non-standard. Like in the Cygwin gcc complier assigment to const varia=
bles result only in a warning at compile time and program runs fine, and pr=
ints out 20!!!.
> #include <stdio.h>
> int main()
> {
> const int i =3D 10;
> i=3D20;
> printf("%d\n",i);
> return 0;
> }/*main*/
> So well although I cannot remember of a third way to do it right now, obv=
iously the first approach is better.
>
>
>
>
> Andr=E9_Mac=E1rio_Barros <and...@su...> wrote:
> Dear Users,
>
> For the sake of flexibility, I think we only have two ways to iniciatize
> a
> size of an array:
> 1) via #define:
> #define MAX 10
> ...
> int vect[MAX];
> ...
>
> 2) via cont variable:
> const int size=3D10;
> ...
> int vetc[size];
> ...
>
> So, in both ways, everytime if I need to change the size of the arrays, i=
t=B4s
> only necessary to change 10 to the other value.
>
> -->My questions:
> 1) Is there more ways to to this?
> 2) For theese two ways presented here, when use one and when use the othe=
r?
> Explaining a little more what I need to know: in a "good programming
> technique"
> point of view, what of theese two is the preferred of the programmers
> (please
> don=B4t answer "pointers" ...lol).
>
> Regards
> Andr=E9
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: eBay
> Get office equipment for less on eBay!
> http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> Thanx and Regards
> Avik Ghose
> Catch all the cricket action. Download Yahoo! Score tracker
|
|
From: Ioannis V. <iv...@em...> - 2003-05-29 18:18:11
|
A third way that guarantees no space occupation by a decent compiler is: const int &SIZE = 7; Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Ioannis V. <iv...@te...> - 2003-05-29 18:17:14
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Avik Ghose
Sent: Thursday, May 29, 2003 8:30 PM
To: Andr?_Macario_Barros; Dev-Cpp-Users
Subject: Re: [Dev-C++] #DEFINE versus cont variables in array
inicializations
Hi Andre,
you are right, there's probably no third way out. Now I prefer to use the
first one due to two reasons.
1> Being textual subsitution, the #define macro does not use up memory size
whereas an integer uses up 32 bytes, though that is negligent for most
purposes.
There is still a 3rd way that guarantees that no size is occupied but i
shall post it in a separate email after this.
2> The more important being that apart from compiler systems that support
C++ along with C, the interpretation of const by the compilers around is a
bit non-standard.
It is standard C++.
Like in the Cygwin gcc complier assigment to const variables result only
in a warning at compile time and program runs fine, and prints out 20!!!.
#include <stdio.h>
int main()
{
const int i = 10;
i=20;
printf("%d\n",i);
return 0;
}/*main*/
So well although I cannot remember of a third way to do it right now,
obviously the first approach is better.
I am bored to check the C standard, bu in C++ that is not allowed (g++, not
gcc).
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
<http://www.noicys.freeurl.com/>
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net <http://www.noicys.cjb.net/>
|
|
From: <a_g...@ya...> - 2003-05-29 17:30:01
|
Hi Andre,
you are right, there's probably no third way out. Now I prefer to use the first one due to two reasons.
1> Being textual subsitution, the #define macro does not use up memory size whereas an integer uses up 32 bytes, though that is negligent for most purposes.
2> The more important being that apart from compiler systems that support C++ along with C, the interpretation of const by the compilers around is a bit non-standard. Like in the Cygwin gcc complier assigment to const variables result only in a warning at compile time and program runs fine, and prints out 20!!!.
#include <stdio.h>
int main()
{
const int i = 10;
i=20;
printf("%d\n",i);
return 0;
}/*main*/
So well although I cannot remember of a third way to do it right now, obviously the first approach is better.
André_Macário_Barros <and...@su...> wrote:
Dear Users,
For the sake of flexibility, I think we only have two ways to iniciatize
a
size of an array:
1) via #define:
#define MAX 10
...
int vect[MAX];
...
2) via cont variable:
const int size=10;
...
int vetc[size];
...
So, in both ways, everytime if I need to change the size of the arrays, it´s
only necessary to change 10 to the other value.
-->My questions:
1) Is there more ways to to this?
2) For theese two ways presented here, when use one and when use the other?
Explaining a little more what I need to know: in a "good programming
technique"
point of view, what of theese two is the preferred of the programmers
(please
don´t answer "pointers" ...lol).
Regards
André
-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
Thanx and Regards
Avik Ghose
Catch all the cricket action. Download Yahoo! Score tracker |
|
From: Ioannis V. <iv...@te...> - 2003-05-29 16:16:48
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of OROSZI Balazs > Sent: Thursday, May 29, 2003 4:32 PM > To: dev...@li... > Subject: Re: [Dev-C++] #DEFINE versus cont variables in array > inicializations > > > > 2) For theese two ways presented here, when use one and > when use the other? > > Well, C++ encourages people to use const variables instead of #define > values. But I think there are circumstances, when #define is > better. In > particular, when you HIGHLY optimize for speed in an > algorithm, and you > don't want to use magic values, then it is better to use > #define values, > as the preprocessor replaces them (as if you had typed in the exact > value) and the compiler can make various optimizations. A good compiler optimises out the const variable when possible (e.g. when not accessed later in a strange way). > For example, when you need to shift with a known value: > > i = 1<<SHIFT_VAL; > > This case it is better to #define SHIFT_VAL 3 for example, > rather than > const int SHIFT_VAL=3, because in the first case the compiler will > automatically calculate the value in compile time: > > i = 1<<3 --> i = 8; > > While this is not true for using const variables (I think, unless the > compiler is smart), and it takes more time to shift with a variable, > rather than with a #define. So, another example: > int v; > v<<SHIFT_VAL; > Here v is a variable, and it is faster to shift it if SHIFT_VAL is a > #define, rather than if SHIFT_VAL is a variable. (I have tested this > extensively!) Both above should be equivalent. > > In your case, I don't think you need this type of low-level > optimisation, so I think you can safely use a const variable. :) At the end we agree. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Ioannis V. <iv...@te...> - 2003-05-29 16:12:20
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Andr? Macario Barros > Sent: Thursday, May 29, 2003 4:09 PM > To: Dev-Cpp-Users > Subject: [Dev-C++] #DEFINE versus cont variables in array=20 > inicializations >=20 >=20 > Dear Users, >=20 > For the sake of flexibility, I think we only have two ways=20 > to iniciatize > a > size of an array: > 1) via #define: > #define MAX 10 > ... > int vect[MAX]; > ... >=20 > 2) via cont variable: > const int size=3D10; > ... > int vetc[size]; > ... The second in C++ only. So please all, explain what programming language = you are referring to, so as to avoid confusions. >=20 > So, in both ways, everytime if I need to change the size of=20 > the arrays, it=B4s The *initial* size of built in arrays... > only necessary to change 10 to the other value. >=20 > -->My questions: > 1) Is there more ways to to this? For built in arrays, no (except of int vetc[10]; of course). > 2) For theese two ways presented here, when use one and when=20 > use the other? Use the second. The first is used in C because the second is not = availlable. Also keep in mind that C and C++ are very different languages now. > Explaining a little more what I need to know: in a "good=20 > programming > technique" > point of view, what of theese two is the preferred of the=20 > programmers The second. But standard library containers should be preferred more. Ioannis Vranos =20 * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Zodiaq <zo...@ac...> - 2003-05-29 14:01:11
|
Hello André and all Dev-C++ users, Thursday, May 29, 2003, 3:08:42 PM, André wrote as follows: AMB> Dear Users, AMB> For the sake of flexibility, I think we only have two ways to iniciatize AMB> a AMB> size of an array: AMB> 1) via #define: AMB> #define MAX 10 AMB> ... AMB> int vect[MAX]; AMB> ... AMB> 2) via cont variable: AMB> const int size=10; AMB> ... AMB> int vetc[size]; AMB> ... AMB> So, in both ways, everytime if I need to change the size of the arrays, it´s AMB> only necessary to change 10 to the other value. -->>My questions: AMB> 1) Is there more ways to to this? enum ?? hehe But what for?? AMB> 2) For theese two ways presented here, when use one and when use the other? AMB> Explaining a little more what I need to know: in a "good programming AMB> technique" AMB> point of view, what of theese two is the preferred of the programmers AMB> (please AMB> don´t answer "pointers" ...lol). AFAIK const is more C++ like, and #define more C like... #define doesn't create 'real' variable, I mean it is only visible in first stage of preprocessing - precompiler raplaces every one of MAX into defined value, program does not see it in runtime... with const it is all different - it is created as variable (which is const), but during runtime you may const_cast it, check for its size, place in memory etc... So I must say I use both ways, but more often the const one... -- regards, Zodiaq |
|
From: <or...@vp...> - 2003-05-29 13:31:00
|
André Macário Barros wrote: > -->My questions: > 1) Is there more ways to to this? To hardcode "magic" values :) But it is not an otpion. > 2) For theese two ways presented here, when use one and when use the other? Well, C++ encourages people to use const variables instead of #define values. But I think there are circumstances, when #define is better. In particular, when you HIGHLY optimize for speed in an algorithm, and you don't want to use magic values, then it is better to use #define values, as the preprocessor replaces them (as if you had typed in the exact value) and the compiler can make various optimizations. For example, when you need to shift with a known value: i = 1<<SHIFT_VAL; This case it is better to #define SHIFT_VAL 3 for example, rather than const int SHIFT_VAL=3, because in the first case the compiler will automatically calculate the value in compile time: i = 1<<3 --> i = 8; While this is not true for using const variables (I think, unless the compiler is smart), and it takes more time to shift with a variable, rather than with a #define. So, another example: int v; v<<SHIFT_VAL; Here v is a variable, and it is faster to shift it if SHIFT_VAL is a #define, rather than if SHIFT_VAL is a variable. (I have tested this extensively!) In your case, I don't think you need this type of low-level optimisation, so I think you can safely use a const variable. Hope I could help. -- Greetings, Balázs |
|
From: <and...@su...> - 2003-05-29 13:08:54
|
Dear Users, For the sake of flexibility, I think we only have two ways to iniciatize a size of an array: 1) via #define: #define MAX 10 ... int vect[MAX]; ... 2) via cont variable: const int size=10; ... int vetc[size]; ... So, in both ways, everytime if I need to change the size of the arrays, it´s only necessary to change 10 to the other value. -->My questions: 1) Is there more ways to to this? 2) For theese two ways presented here, when use one and when use the other? Explaining a little more what I need to know: in a "good programming technique" point of view, what of theese two is the preferred of the programmers (please don´t answer "pointers" ...lol). Regards André |