OSDN Git Service

* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
[pf3gnuchains/gcc-fork.git] / libgfortran / intrinsics / size.c
1 /* Implementation of the size intrinsic.
2    Copyright 2002 Free Software Foundation, Inc.
3    Contributed by Paul Brook <paul@nowt.org>
4
5 This file is part of the GNU Fortran 95 runtime library (libgfor).
6
7 Libgfor is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 Libgfor is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB.  If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "libgfortran.h"
23
24 index_type
25 size0 (const array_t * array)
26 {
27   int n;
28   index_type size;
29   index_type len;
30
31   size = 1;
32   for (n = 0; n < GFC_DESCRIPTOR_RANK (array); n++)
33     {
34       len = array->dim[n].ubound + 1 - array->dim[n].lbound;
35       if (len < 0)
36         len = 0;
37       size *= len;
38     }
39   return size;
40 }
41 iexport(size0);
42
43 extern index_type size1 (const array_t * array, index_type dim);
44 export_proto(size1);
45
46 index_type
47 size1 (const array_t * array, index_type dim)
48 {
49   index_type size;
50
51   dim--;
52
53   size = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
54   if (size < 0)
55     size = 0;
56   return size;
57 }