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:43:58
|
> -----Original Message----- > From: Ioannis Vranos [mailto:no...@ho...] > Sent: Friday, October 25, 2002 12:39 PM > To: Dev-C++ Mailing List (dev...@li...) > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > -----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. Also i cannot understand why someone would create a single dimensional array of pointers on the free store and then assign an element on the free store to each of them. It's a total waste of everything. :) Using a simple pointer and allocating space for the elements directly on the free store would be a reasonable thing to do. /* Array of 100 mystructs on the free store */ struct mystruct *p=malloc(100*sizeof(*p)); Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |