Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
EXTERN_C_EXCEPTIONS.cpp
Go to the documentation of this file.
1// checking for exceptions from extern "C" functions
2
3
25// test tries to determine whether it's possible to throw exceptions
26// from functions with C language linkage
27
28extern "C" {
29
30int extern_c_function (int x, int y, int (*fun)(int, int))
31{
32 if (fun)
33 return fun (x, y);
34
35 return 0;
36
37}
38
39int div_throw (int x, int y)
40{
41 if (0 == y)
42 throw y;
43
44 return x / y;
45}
46
47int div_nothrow (int x, int y)
48{
49 if (0 == y)
50 return 0;
51
52 return x / y;
53
54}
55
56typedef int cfun_t (int, int);
57
58
59} // extern "C"
60
61
62int main (int argc, char *argv[])
63{
64 const int x = argc < 2 ? 0 : int (*argv [1]);
65 const int y = argc < 3 ? 0 : int (*argv [2]);
66
67 cfun_t* pcfun = argc < 4 ? div_throw : div_nothrow;
68
69 int result;
70
71 try {
72 result = extern_c_function (x, y, pcfun);
73 }
74 catch (int res) {
75 result = res;
76 }
77
78 return result;
79}
#define y
Definition 17.names.cpp:141
#define fun
Definition 17.names.cpp:471
#define res
Definition 17.names.cpp:531
#define x
Definition 17.names.cpp:140
volatile int result
#define main
int div_throw(int x, int y)
int cfun_t(int, int)
int extern_c_function(int x, int y, int(*fun)(int, int))
int div_nothrow(int x, int y)