Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
COMS327
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jake Feddersen
COMS327
Commits
148120fe
Commit
148120fe
authored
6 years ago
by
Jake Feddersen
Browse files
Options
Downloads
Patches
Plain Diff
Notes
parent
d7df0c0e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
notes/2_20/macros.c
+59
-0
59 additions, 0 deletions
notes/2_20/macros.c
notes/2_22/jump_table
+0
-0
0 additions, 0 deletions
notes/2_22/jump_table
notes/2_22/jump_table.c
+46
-0
46 additions, 0 deletions
notes/2_22/jump_table.c
with
105 additions
and
0 deletions
notes/2_20/macros.c
0 → 100644
+
59
−
0
View file @
148120fe
//#include <stdio.h>
#define NPC_SMART 0x00000001
#define NPC_TELE 0x00000002
#define NPC_TUNNEL 0x00000004
#define NPC_ERRATIC 0x00000008
#define MAX_ROOMS 20
#define NOTHING
#define to_string(s) #s
#define table_element(e) { e, #e }
struct
{
int
,
char
*
}
table
[]
=
{
table_element
(
i
);
table_element
(
j
);
};
#define has_characteristic(character, bit) \
((character) & NPC_##bit)
#ifdef NOTHING
int
Idontmatter
=
MAX_ROOMS
;
#endif
// Not the best, evalues each argument twice
#define min(x, y) (x < y ? x : y)
int
characteristics
=
rand
()
%
16
;
// Better, evaluates each argument once and uses those results
#define max(x, y) ({ \
typeof (x) _x = x; \
typeof (y) _y = y; \
_x > _y ? _x : _y; \
})
int
main
(
int
argc
,
char
*
argv
[])
{
MAX_ROOMS
;
min
(
3
,
4
);
#if 0
min(foo(x), bar(x));
max(foo(x), bar(x));
if (10 > min(foo(x), bar(x))) {
}
#endif
int
x
=
NOTHING
;
if
(
has_characteristic
(
characteristic
,
SMART
))
{
// This is a smart monster
}
else
{
// This is a not smart monster
}
to_string
(
Foo
);
return
0
;
}
This diff is collapsed.
Click to expand it.
notes/2_22/jump_table
0 → 100755
+
0
−
0
View file @
148120fe
File added
This diff is collapsed.
Click to expand it.
notes/2_22/jump_table.c
0 → 100644
+
46
−
0
View file @
148120fe
#include
<stdio.h>
// Type func: pointer to function that returns void and takes void
typedef
void
(
*
func
)(
void
);
void
zero
()
{
printf
(
__FUNCTION__
);
}
void
one
()
{
printf
(
__FUNCTION__
);
}
void
two
()
{
printf
(
__FUNCTION__
);
}
void
three
()
{
printf
(
__FUNCTION__
);
}
void
four
()
{
printf
(
__FUNCTION__
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
func
table
[]
=
{
zero
,
one
,
two
,
three
,
four
};
int
i
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
table
[
i
]();
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment