~ubuntu-branches/ubuntu/utopic/critcl/utopic

« back to all changes in this revision

Viewing changes to examples/stack/stackc/util.h

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura
  • Date: 2013-05-11 00:08:06 UTC
  • Revision ID: package-import@ubuntu.com-20130511000806-7hq1zc3fnn0gat79
Tags: upstream-3.1.9
ImportĀ upstreamĀ versionĀ 3.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* stackc - critcl - layer 0 declarations
 
2
 * API general utilities
 
3
 */
 
4
 
 
5
#ifndef _UTIL_H
 
6
#define _UTIL_H 1
 
7
 
 
8
#include <tcl.h>
 
9
 
 
10
/* Allocation macros for common situations.
 
11
 */
 
12
 
 
13
#define ALLOC(type)    (type *) ckalloc (sizeof (type))
 
14
#define NALLOC(n,type) (type *) ckalloc ((n) * sizeof (type))
 
15
 
 
16
/* Assertions in general, and asserting the proper range of an array index.
 
17
 */
 
18
 
 
19
#undef  STACKC_DEBUG
 
20
#define STACKC_DEBUG 1
 
21
 
 
22
#ifdef STACKC_DEBUG
 
23
#define XSTR(x) #x
 
24
#define STR(x) XSTR(x)
 
25
#define RANGEOK(i,n) ((0 <= (i)) && (i < (n)))
 
26
#define ASSERT(x,msg) if (!(x)) { Tcl_Panic (msg " (" #x "), in file " __FILE__ " @line " STR(__LINE__));}
 
27
#define ASSERT_BOUNDS(i,n) ASSERT (RANGEOK(i,n),"array index out of bounds: " STR(i) " > " STR(n))
 
28
#else
 
29
#define ASSERT(x,msg)
 
30
#define ASSERT_BOUNDS(i,n)
 
31
#endif
 
32
 
 
33
#endif /* _UTIL_H */
 
34
 
 
35
/*
 
36
 * Local Variables:
 
37
 * mode: c
 
38
 * c-basic-offset: 4
 
39
 * fill-column: 78
 
40
 * End:
 
41
 */