size_from_kind.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright (C) 2005-2015 Free Software Foundation, Inc.
  2. Contributed by Janne Blomqvist
  3. This file is part of the GNU Fortran runtime library (libgfortran).
  4. Libgfortran is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. Libgfortran is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* This file contains utility functions for determining the size of a
  20. variable given its kind. */
  21. #include "io.h"
  22. size_t
  23. size_from_real_kind (int kind)
  24. {
  25. switch (kind)
  26. {
  27. #ifdef HAVE_GFC_REAL_4
  28. case 4:
  29. return sizeof (GFC_REAL_4);
  30. #endif
  31. #ifdef HAVE_GFC_REAL_8
  32. case 8:
  33. return sizeof (GFC_REAL_8);
  34. #endif
  35. #ifdef HAVE_GFC_REAL_10
  36. case 10:
  37. return sizeof (GFC_REAL_10);
  38. #endif
  39. #ifdef HAVE_GFC_REAL_16
  40. case 16:
  41. return sizeof (GFC_REAL_16);
  42. #endif
  43. default:
  44. return kind;
  45. }
  46. }
  47. size_t
  48. size_from_complex_kind (int kind)
  49. {
  50. switch (kind)
  51. {
  52. #ifdef HAVE_GFC_COMPLEX_4
  53. case 4:
  54. return sizeof (GFC_COMPLEX_4);
  55. #endif
  56. #ifdef HAVE_GFC_COMPLEX_8
  57. case 8:
  58. return sizeof (GFC_COMPLEX_8);
  59. #endif
  60. #ifdef HAVE_GFC_COMPLEX_10
  61. case 10:
  62. return sizeof (GFC_COMPLEX_10);
  63. #endif
  64. #ifdef HAVE_GFC_COMPLEX_16
  65. case 16:
  66. return sizeof (GFC_COMPLEX_16);
  67. #endif
  68. default:
  69. return 2 * kind;
  70. }
  71. }