xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/test-function.c (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright (c) 2019, Joyent, Inc.
14  * Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
15  */
16 
17 #include <sys/types.h>
18 #include <string.h>
19 
20 /*
21  * Test various function and function pointer cases.
22  */
23 
24 void
25 simple_func(void)
26 {
27 }
28 
29 void
30 one(int v)
31 {
32 }
33 
34 void
35 two(int v, const char *a)
36 {
37 }
38 
39 void
40 three(int v, const char *a, float b)
41 {
42 }
43 
44 const char *
45 noarg(void)
46 {
47 	return ("hello, world");
48 }
49 
50 const char *
51 argument(uintptr_t base)
52 {
53 	return ((const char *)(base + 1));
54 }
55 
56 void
57 vararg(const char *foo, ...)
58 {
59 
60 }
61 
62 uintptr_t
63 vararg_ret(const char *foo, ...)
64 {
65 	return ((uintptr_t)foo);
66 }
67 
68 int
69 vla1(int n, int arr[n])
70 {
71 	return (arr[1]);
72 }
73 
74 int
75 vla2(int n, int arr[n][n])
76 {
77 	return (arr[1][2]);
78 }
79 
80 int
81 vla3(int n, int arr[n][7])
82 {
83 	return (arr[1][2]);
84 }
85 
86 int
87 vla4(int n, int arr[23][n])
88 {
89 	return (arr[1][2]);
90 }
91 
92 int
93 vla5(int a, int b, int arr[a][3][b])
94 {
95 	return (arr[1][2][3]);
96 }
97 
98 int
99 vla6(int a, int b, int arr[a][b][4])
100 {
101 	return (arr[1][2][3]);
102 }
103 
104 typedef int (*strfunc_t)(const char *, const char *);
105 typedef void (*vararg_t)(const char *, ...);
106 
107 strfunc_t s = strcmp;
108 vararg_t v = vararg;
109