RE: [Dev-C++] dynamic allocation and structs
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-10-25 09:38:54
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Friday, October 25, 2002 11:51 AM > To: Ioannis Vranos > Cc: 'Dev-C++ Mailing List' > Subject: RE: [Dev-C++] dynamic allocation and structs > > > The trick is that vector isn't programming. It is a standard > - and very > old - mathematical term for a one-dimensional matrix. Yes, but when we speak of C++ code, calling a built in array a "vector" can only be confusing. > There has been > millions of vector implementations before STL did a template > version, and > the probability of a finding a STL construct in a C program > is not that > high :-) Yes, but it still can be confusing to C++ programmers. > > While code might syntactically switch around between > (*a).x, > a->x > a[0].x > > the third form is definitely dangerous to use when a is only > a pointer to > a single element. If there is an element zero, the logical > conclusion is > that there must be a element one. Yes, if there is only one element i would use the -> only. When we have more the [] is more suitable. Both are valid. > > While one goal of programming is to make the programs work, > it shouldn't > be neglected that comming generations of programmers > inherriting old code > does immediately see what the code does. When seeing a x[0] > statement, the > natural reaction is - or should be - to start hunt for the > total size of > the vector. Yes. However i did created a 200x100 array on the free store so the second [] was suitable. :) Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |