main.hh
author Mario de Sousa <msousa@fe.up.pt>
Wed, 26 Dec 2018 11:56:14 +0000
changeset 1082 903e2782e405
parent 1014 a61f8f58f612
permissions -rw-r--r--
fix bug introduced in previous commit (force literals to unsigned log long)
597
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     1
/*
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     3
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     4
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     5
 *
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     9
 *  (at your option) any later version.
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    10
 *
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    14
 *  GNU General Public License for more details.
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    15
 *
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    18
 *
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    19
 *
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    22
 */
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    23
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    24
/*
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    25
 * An IEC 61131-3 compiler.
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    26
 *
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    27
 * Based on the
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    29
 *
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    30
 */
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    31
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    32
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    33
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    34
#ifndef _MAIN_HH
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    35
#define _MAIN_HH
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    36
604
2989051a0a64 Fixing includes to define INTxx_MAX etc...
Mario de Sousa <msousa@fe.up.pt>
parents: 597
diff changeset
    37
2989051a0a64 Fixing includes to define INTxx_MAX etc...
Mario de Sousa <msousa@fe.up.pt>
parents: 597
diff changeset
    38
946
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    39
/* Compiler options, specified at runtime on the command line */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    40
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    41
typedef struct {
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    42
   /* options specific to stage1_2 */
1014
a61f8f58f612 Add support for non-standard VOID datatype. May ony be used to define functions returning VOID.
mjsousa
parents: 1012
diff changeset
    43
	bool allow_void_datatype;      /* Allow declaration of functions returning VOID  */
1012
1f2af384fb1f Add support for non standard feature: allow POUs with no in, out and inout parameters
mjsousa
parents: 1011
diff changeset
    44
	bool allow_missing_var_in;     /* Allow definition and invocation of POUs with no input, output and in_out parameters! */
1011
76175defb87b Add option to not add the EN and ENO parameters to every function and FB (generated C code becomes smaller, and uses less memory for function invocations)
mjsousa
parents: 980
diff changeset
    45
	bool disable_implicit_en_eno;  /* Disable the generation of implicit EN and ENO parameters on functions and Function Blocks */
956
513809fbfaf9 Make use of pre-parser a command line option.
mjsousa
parents: 946
diff changeset
    46
	bool pre_parsing;              /* Support forward references (Run a pre-parsing phase before the defintive parsing phase that builds the AST) */
946
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    47
	bool safe_extensions;          /* support SAFE_* datatypes defined in PLCOpen TC5 "Safety Software Technical Specification - Part 1" v1.0 */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    48
	bool full_token_loc;           /* error messages specify full token location */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    49
	bool conversion_functions;     /* Create a conversion function for derived datatype */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    50
	bool nested_comments;          /* Allow the use of nested comments. */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    51
	bool ref_standard_extensions;  /* Allow the use of REFerences (keywords REF_TO, REF, DREF, ^, NULL). */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    52
	bool ref_nonstand_extensions;  /* Allow the use of non-standard extensions to REF_TO datatypes: REF_TO ANY, and REF_TO in struct elements! */
980
9ed5aff159db Make support for use of variables in array size declarations a command line option (off by default)
mjsousa
parents: 956
diff changeset
    53
	bool nonliteral_in_array_size; /* Allow the use of constant non-literals when specifying size of arrays (ARRAY [1..max] OF INT) */
946
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    54
	const char *includedir;        /* Include directory, where included files will be searched for... */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    55
	
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    56
   /* options specific to stage3 */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    57
	bool relaxed_datatype_model;   /* Use the relaxed datatype equivalence model, instead of the default strict equivalence model */
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    58
} runtime_options_t;
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    59
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    60
extern runtime_options_t runtime_options;
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    61
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    62
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    63
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    64
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    65
c012a64dc2fa Make the relaxed datatype model a runtime option (off by default)
mjsousa
parents: 890
diff changeset
    66
597
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    67
 /* Function used throughout the code --> used to report failed assertions (i.e. internal compiler errors)! */
604
2989051a0a64 Fixing includes to define INTxx_MAX etc...
Mario de Sousa <msousa@fe.up.pt>
parents: 597
diff changeset
    68
#include <stddef.h>  /* required for NULL */
2989051a0a64 Fixing includes to define INTxx_MAX etc...
Mario de Sousa <msousa@fe.up.pt>
parents: 597
diff changeset
    69
 
597
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    70
#define ERROR               error_exit(__FILE__,__LINE__)
654
7421cb63defa list_c: initial capacity. ERROR_MSG(msg,...) supports optional arguments now.
agraeper
parents: 645
diff changeset
    71
#define ERROR_MSG(msg, ...) error_exit(__FILE__,__LINE__, msg, ## __VA_ARGS__)
597
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    72
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    73
extern void error_exit(const char *file_name, int line_no, const char *errmsg = NULL, ...);
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    74
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    75
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    76
7326a0658104 Add file missing from previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    77
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    78
 /* Get the definition of INT16_MAX, INT16_MIN, UINT64_MAX, INT64_MAX, INT64_MIN, ... */
760
d736dc9e9e51 Protect against redefining macros
mjsousa
parents: 654
diff changeset
    79
#ifndef __STDC_LIMIT_MACROS
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    80
#define __STDC_LIMIT_MACROS /* required to have UINTxx_MAX defined when including stdint.h from C++ source code. */
760
d736dc9e9e51 Protect against redefining macros
mjsousa
parents: 654
diff changeset
    81
#endif
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    82
#include <stdint.h>         
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    83
#include <limits>
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    84
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    85
#ifndef   UINT64_MAX 
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    86
  #define UINT64_MAX (std::numeric_limits< uint64_t >::max())
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    87
#endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    88
#ifndef    INT64_MAX 
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    89
  #define  INT64_MAX (std::numeric_limits<  int64_t >::max())
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    90
#endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    91
#ifndef    INT64_MIN
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    92
  #define  INT64_MIN (std::numeric_limits<  int64_t >::min()) 
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    93
#endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    94
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    95
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    96
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    97
/* Determine, for the current platform, which datas types (float, double or long double) use 64 and 32 bits. */
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    98
/* NOTE: We cant use sizeof() in pre-processor directives, so we have to do it another way... */
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
    99
/* CURIOSITY: We can use sizeof() and offsetof() inside static_assert() but:
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   100
 *          - this only allows us to make assertions, and not #define new macros
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   101
 *          - is only available in the C standard [ISO/IEC 9899:2011] and the C++ 0X draft standard [Becker 2008]. It is not available in C99.
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   102
 *          https://www.securecoding.cert.org/confluence/display/seccode/DCL03-C.+Use+a+static+assertion+to+test+the+value+of+a+constant+expression
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   103
 *         struct {int a, b, c, d} header_t;
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   104
 *  e.g.:  static_assert(offsetof(struct header_t, c) == 8, "Compile time error message.");
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   105
 */
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   106
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   107
#include <float.h>
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   108
#if    (LDBL_MANT_DIG == 53) /* NOTE: 64 bit IEC559 real has 53 bits for mantissa! */
890
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   109
  #define real64_tX long_double /* so we can later use #if (real64_t == long_double) directives in the code! */
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   110
  #define real64_t  long double /* NOTE: no underscore '_' between 'long' and 'double' */
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   111
  #define REAL64_MAX  LDBL_MAX
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   112
#elif  ( DBL_MANT_DIG == 53) /* NOTE: 64 bit IEC559 real has 53 bits for mantissa! */
890
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   113
  #define real64_tX double
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   114
  #define real64_t  double
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   115
  #define REAL64_MAX  DBL_MAX
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   116
#elif  ( FLT_MANT_DIG == 53) /* NOTE: 64 bit IEC559 real has 53 bits for mantissa! */
890
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   117
  #define real64_tX float
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   118
  #define real64_t  float
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   119
  #define REAL64_MAX  FLT_MAX
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   120
#else 
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   121
  #error Could not find a 64 bit floating point data type on this platform. Aborting...
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   122
#endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   123
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   124
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   125
#if    (LDBL_MANT_DIG == 24) /* NOTE: 32 bit IEC559 real has 24 bits for mantissa! */
890
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   126
  #define real32_tX long_double /* so we can later use #if (real32_t == long_double) directives in the code! */
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   127
  #define real32_t  long double /* NOTE: no underscore '_' between 'long' and 'double' */
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   128
  #define REAL32_MAX  LDBL_MAX
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   129
#elif  ( DBL_MANT_DIG == 24) /* NOTE: 32 bit IEC559 real has 24 bits for mantissa! */
890
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   130
  #define real32_tX double
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   131
  #define real32_t  double
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   132
  #define REAL32_MAX  DBL_MAX
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   133
#elif  ( FLT_MANT_DIG == 24) /* NOTE: 32 bit IEC559 real has 24 bits for mantissa! */
890
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   134
  #define real32_tX float
499486ece119 Fix compilation error on platforms where real64_t is mapped onto 'long double'
mjsousa
parents: 760
diff changeset
   135
  #define real32_t  float
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   136
  #define REAL32_MAX  FLT_MAX
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   137
#else 
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   138
  #error Could not find a 32 bit floating point data type on this platform. Aborting...
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   139
#endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   140
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   141
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   142
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   143
#include <math.h>
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   144
#ifndef INFINITY
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   145
  #error Could not find the macro that defines the value for INFINITY in the current platform.
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   146
#endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   147
#ifndef NAN
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   148
  #error Could not find the macro that defines the value for NAN in the current platform.
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   149
#endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   150
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   151
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   152
645
e01ede1c9862 Allow the use of PRId64, PRIu64 and PRIx64 printf formating macros globally.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   153
/* get the printf format macros for printing variables of fixed data size
e01ede1c9862 Allow the use of PRId64, PRIu64 and PRIx64 printf formating macros globally.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   154
 * e.g.  int64_t v; printf("value=%"PRId64" !!\n", v);
e01ede1c9862 Allow the use of PRId64, PRIu64 and PRIx64 printf formating macros globally.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   155
 * e.g. uint64_t v; printf("value=%"PRIu64" !!\n", v);
e01ede1c9862 Allow the use of PRId64, PRIu64 and PRIx64 printf formating macros globally.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   156
 * e.g. uint64_t v; printf("value=%"PRIx64" !!\n", v);  // hexadecimal format
e01ede1c9862 Allow the use of PRId64, PRIu64 and PRIx64 printf formating macros globally.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   157
 */
760
d736dc9e9e51 Protect against redefining macros
mjsousa
parents: 654
diff changeset
   158
#ifndef __STDC_FORMAT_MACROS
645
e01ede1c9862 Allow the use of PRId64, PRIu64 and PRIx64 printf formating macros globally.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   159
#define __STDC_FORMAT_MACROS
760
d736dc9e9e51 Protect against redefining macros
mjsousa
parents: 654
diff changeset
   160
#endif
645
e01ede1c9862 Allow the use of PRId64, PRIu64 and PRIx64 printf formating macros globally.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   161
#include <inttypes.h>
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   162
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 604
diff changeset
   163
654
7421cb63defa list_c: initial capacity. ERROR_MSG(msg,...) supports optional arguments now.
agraeper
parents: 645
diff changeset
   164
#endif // #ifndef _MAIN_HH