Context algorithm
Semi-predictive context algorithm implementation
 All Data Structures Files Functions Variables Typedefs Macros Pages
spacedef.h
Go to the documentation of this file.
1 /* Copyright 2013 Jorge Merlino
2 
3  This file is part of Context.
4 
5  Context is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Context is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Context. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef SPACEDEF_H
20 #define SPACEDEF_H
21 #include <string.h>
22 #include "types.h"
23 
24 
32 #define REALLOCSPACE(S,T,N)\
33  (T *) realloc(S,sizeof(T) * (size_t) (N))
34 
35 
43 #define REALLOC(V,S,T,N)\
44  V = REALLOCSPACE(S,T,N);\
45  if((V) == NULL)\
46  {\
47  fprintf(stderr,"file %s, line %lu: realloc(%lu) failed\n",\
48  __FILE__,(Showuint) __LINE__,\
49  (Showuint) (sizeof(T) * (size_t) (N)));\
50  exit(EXIT_FAILURE);\
51  }
52 
53 
58 #define FREE(P)\
59  if((P) != NULL)\
60  {\
61  free(P);\
62  P = NULL;\
63  }
64 
65 
72 #define CALLOC(S,T,N)\
73  S = calloc(sizeof(T), N);\
74  if ((S) == NULL) {\
75  fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n",\
76  __FILE__,(Showuint) __LINE__,\
77  (Showuint) (sizeof(T) * (size_t) (N)));\
78  exit(EXIT_FAILURE);\
79  }
80 
81 #define MALLOC(S,T,N)\
82  S = malloc(sizeof(T) * N);\
83  if ((S) == NULL) {\
84  fprintf(stderr,"file %s, line %lu: calloc(%lu) failed\n",\
85  __FILE__,(Showuint) __LINE__,\
86  (Showuint) (sizeof(T) * (size_t) (N)));\
87  exit(EXIT_FAILURE);\
88  }
89 
90 #endif