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 08:03:21
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Friday, October 25, 2002 10:53 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] dynamic allocation and structs > > > The term vector is valid, since the allocated information is > only supposed > to be used with one single index, i.e. one-dimensional. I said avoid using the term "vector" for built-in arrays so as to not confuse them with C++'s standard library vectors. Call them "built in arrays". > It must always be observed - yes this is outside scope of Dev-C++ but > standard C/C++ requirements - that a while a pointer might > point to the > forst element of a vector, i.e. > mystruct *p; > p[0].x = 1; > p[1].x = 2; > ... > it is not required or guaranteed that there are more than one > element the > pointer is pointing at. Never assume a p[1] just because p[0] is fine. > The code below uses vector[i]->id, not vector[i][0].id, to > signify that > this is a one-dimensional allocation, and that while the > compiler would > accept vector[i][0], vector[i][1], vector[i][1] would point outside > allocated memory. i think the second [] swits better notationally. It's a personal taste. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |