forked from shihyu/DesignPatternExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget.c
More file actions
42 lines (31 loc) · 617 Bytes
/
Copy pathtarget.c
File metadata and controls
42 lines (31 loc) · 617 Bytes
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
38
39
40
41
42
#include <stdio.h>
#include "itarget.h"
#include "target.h"
static long Target_powerOf2(ITarget*, int);
Target* Target_construct(void* addr)
{
if (addr == NULL) {
return NULL;
}
Target* target = addr;
target->powerOf2 = Target_powerOf2;
return target;
}
void Target_destruct(Target* target)
{
}
long Target_powerOf2(ITarget* itarget, int exp)
{
if (exp < 0) {
fprintf(stderr, "Do not support negative exponent.\n");
return -1;
}
if (exp == 0) {
return 1;
}
long sum = 1;
while (exp--) {
sum <<= 1;
}
return sum;
}