Prev: practice online trading. platinum online trading. online trading worldwide. online trading which is best
Next: variant data type
From: glen herrmannsfeldt on 30 Jun 2010 21:34 Ron Shepard <ron-shepard(a)nospam.comcast.net> wrote: (snip, I wrote) >> I believe that C99 has variable dimension automatic arrays. >> I haven't tried them yet. > Can you allocate these multidimensional arrays with malloc() (or > some other library routine) in the same routine that they are used? > In older versions of C, malloc() would only allocate 1D arrays, and > the programmer had to restort to various pointer tricks to mimic > using it as a multidimensional array. Well, malloc() allocates memory, what you do with the allocated memory is a different question. In C terms, the question, then, is the ability to have a pointer to two dimensional variable sized data. I don't know if C99 can do that or not. You might call it a trick, but the common method is an array of pointers, which is legal and also advantageous when the memory needed isn't rectangular. It is a convenience of C that a reference to such looks the same as a reference to a 2D array. It was also useful in the 80286 days when allocating arrays bigger than 64K, but where each column was smaller than 64K. I had programs running on OS/2 1.0 and 1.2 using many megabytes easily, when most were running DOS in 640K. > And some of those pointer > tricks were, strictly speaking, illegal in the language. As I said > before, claiming that as a "feature" of the language is like trying > to make a liability sound like an asset. The trick used in "Numerical Recipes" so they could translate their Fortran programs with 1 origin arrays to C without fixing the origin is, strictly, illegal, though it works in just about all systems. (As do many Fortran array tricks unless bounds checking is turned on.) As I remember it, the PDP-11 Fortran compilers addressed 2D arrays though an array of addresses, that being faster than doing the multiply that was otherwise required. For newer hardware it is likely that a multiply is faster than a memory reference. -- glen
From: glen herrmannsfeldt on 30 Jun 2010 21:37 Lynn McGuire <lmc(a)winsim.com> wrote: (snip) > 48 bit char pointer and 32 bit integer pointer, nasty ! > When we ported our fortran to the IBM mainframe from the Univac 1108 > in 1975, we ran into a major problem. All of the machines that we > had supported to that date were 36 bits or more using 6 bit bytes. > So, our hollerith had 6HABCDEF all over the place. We had to > change that to 4HABCD plus 2HEF. It was a major effort to change. Some might have instead used REAL*8 (or DOUBLE PRECISION). It is convenient of S/360 not to normalize data on load store operations. -- glen
From: Jugoslav Dujic on 1 Jul 2010 07:30 On 29.06.2010. 23:22, Colin Watters wrote: > Here is an even more dated paper (1893) comparing Fortran and some other > languages: Jeez, I didn't know Fortran is *THAT* old :o) -- Jugoslav www.xeffort.com
From: blmblm on 1 Jul 2010 08:36 In article <7XsWn.305$5N3.154(a)bos-service2b.ext.ray.com>, Steve Fry <scfry(a)raytheon.com> wrote: > "rfengineer55" asked this question: > > What can Fortran do that C, C++, C# can't? > > > > Along similar lines where would Fortran be a superior chice over C, C+ > > +, or C# > > > > Since the CPUs on todays computers are not getting any faster (as was > promised 20 years ago), "As was promised"? What am I not thinking of here? (And why would you believe a promise that single processors would continue to get faster forever?) Or maybe you mean that 20 years ago advocates of parallel computing were already saying that there were limits on the speed of a single processor, so the future was parallel? That's what I remember, and while it has taken longer than they might have thought, we may be there now? > my main concern is what will crunch numbers faster. > > So which compiler or language is best suited for faster processing? -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
From: blmblm on 1 Jul 2010 08:38
In article <ron-shepard-BBD726.10503830062010(a)forte.easynews.com>, Ron Shepard <ron-shepard(a)NOSPAM.comcast.net> wrote: > In article <i0fli7$hq9$1(a)speranza.aioe.org>, > glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote: > > > Ron Shepard <ron-shepard(a)nospam.comcast.net> wrote: > > (snip) > > > > > Even though fortran does support these kinds of data structures, it is > > > often better to avoid them. Allocatable arrays in fortran, for example, > > > have several advantages over the analogous pointer approach, and that is > > > often the preferred data type given the various options. As far as I > > > know, even modern C does not support multidimensional allocatable > > > arrays, and it gives the programmer no control over the lower bounds > > > within the array, so it is some 30+ years behind fortran in some ways, > > > and 20+ years behind fortran in others. I don't know about the latest > > > version of the other languages in this thread title in this respect. > > > > I believe that C99 has variable dimension automatic arrays. > > I haven't tried them yet. Yes. They're called VLAs ("variable-length arrays"). Simple example below. > Can you allocate these multidimensional arrays with malloc() (or > some other library routine) in the same routine that they are used? No, they're not explicitly allocated, but automatic, meaning that space for them is (as far as I know) allocated from the same pool used for local variables -- typically "the stack". That has its advantages but also its disadvantages. Indexing is still, again as far as I know, zero-based, which is a pain. > In older versions of C, malloc() would only allocate 1D arrays, and > the programmer had to restort to various pointer tricks to mimic > using it as a multidimensional array. And some of those pointer > tricks were, strictly speaking, illegal in the language. As I said > before, claiming that as a "feature" of the language is like trying > to make a liability sound like an asset. Agreed. Complete though terse example (which compiles with gcc under Linux -- though you need the "-std=c99" flag): #include <stdio.h> #include <stdlib.h> /* fill n by m array */ void fill(size_t n, size_t m, int a[m][n]) { for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) a[i][j] = i+j; } /* print n by m array */ void print(size_t n, size_t m, int a[m][n]) { for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) printf("a[%d][%d] = %d\n", i, j, a[i][j]); } /* main program */ /* command-line arguments n, m specify dimensions of array */ int main(int argc, char* argv[]) { /* error handling code for command-line arguments omitted */ int n = atoi(argv[1]); int m = atoi(argv[2]); int a[n][m]; fill(n, m, a); print(n, m, a); return 0; } -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor. |