repo.or.cz
/
sdcc.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
struct / union in initializer, RFE #901.
[sdcc.git]
/
sdcc
/
support
/
regression
/
tests
/
satcounteroverflow.c.in
blob
b22887c302a6259ada676aa8cbcbff5d6063caca
1
/** user-implemented saturating counters using unsigned integer wraparound
2
3
type: unsigned char, unsigned int, unsigned long
4
*/
5
6
#include <testfwk.h>
7
8
{
type
}
cnt
;
9
10
void
satinc
(
void
)
11
{
12
cnt
++;
13
if
(!
cnt
)
14
cnt
--;
15
}
16
17
void
satdec
(
void
)
18
{
19
cnt
--;
20
if
(
cnt
== ({
type
})-
1
)
21
cnt
++;
22
}
23
24
void
testSat
(
void
)
25
{
26
cnt
=
0
;
27
satinc
();
28
ASSERT
(
cnt
==
1
);
29
satdec
();
30
satdec
();
31
ASSERT
(
cnt
==
0
);
32
33
cnt
= -
2
;
34
satinc
();
35
ASSERT
(
cnt
== ({
type
})-
1
);
36
satinc
();
37
ASSERT
(
cnt
== ({
type
})-
1
);
38
}
39