File: function-ptr-xtype.c

package info (click to toggle)
sparse 0.6.4-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,868 kB
  • sloc: ansic: 46,050; sh: 614; python: 301; perl: 293; makefile: 279
file content (37 lines) | stat: -rw-r--r-- 819 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
typedef int  (*binop_t)(int, int);
typedef int  (*unop_t)(int);
typedef int  (*idef_t)(void);
typedef long (*ldef_t)(void);
typedef void (*use_t)(int);

// We want to 'fn' have several different types.
// The goal is for the ->priv member to be used
// with a type different from what it was first stored.

int foo(void *fn, int arg1, int arg2);
int foo(void *fn, int arg1, int arg2)
{
	int res = 0;

	res += ((binop_t)fn)(arg1, arg2);
	res += ((unop_t)fn)(arg1);
	res += ((ldef_t)fn)();
	res += ((idef_t)fn)();
	((use_t)fn)(res);
	return res;
}

int bar(int (*fn)(int), int arg1, int arg2);
int bar(int (*fn)(int), int arg1, int arg2)
{
	int res = 0;

	res += ((binop_t)fn)(arg1, arg2);
	res += fn(arg1);
	return res;
}

/*
 * check-name: mutate function pointer's type
 * check-command: sparsec -c $file -o tmp.o
 */