Skip to content

Commit e517bec

Browse files
committed
Fixing warnings in wefx code moving to c11
1 parent 2875b18 commit e517bec

File tree

8 files changed

+56
-35
lines changed

8 files changed

+56
-35
lines changed

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ PANDOC?=pandoc
77
NARRATIVE?=narrative
88
MAIN?=examples/example0.c
99

10+
C_ERRS += -Wall -Wextra -Wpedantic \
11+
-Wformat=2 -Wno-unused-parameter -Wshadow \
12+
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \
13+
-Wredundant-decls -Wnested-externs -Wmissing-include-dirs \
14+
-Wno-unused
15+
1016
NO_BUILT_INS=-fno-builtin-sin -fno-builtin-cos -fno-builtin-tan \
1117
-fno-builtin-ceil -fno-builtin-floor \
1218
-fno-builtin-pow -fno-builtin-round \
@@ -35,10 +41,9 @@ clean:
3541

3642
build: clean
3743
mkdir -p build
38-
$(CC) \
44+
$(CC) $(C_ERRS) \
3945
--target=wasm32 \
40-
-std=c99 \
41-
-Wall \
46+
-std=c11 \
4247
-g \
4348
-nostdlib \
4449
-Os -flto \
@@ -82,7 +87,7 @@ test: clean_test
8287

8388
mkdir -p build
8489
# add -lm if you want to test against built in math.h
85-
$(CC) -std=c99 -m32 -g \
90+
$(CC) $(C_ERRS) -std=c11 -m32 -g \
8691
$(NO_BUILT_INS) \
8792
src/math.c src/wefx.c src/test.c \
8893
-o build/test

README.md

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
# wefx
22

3-
Wefx is a simple graphics library for drawing using C, WASM ([Web Assembly][webassembly]), and an [HTML canvas][htmlcanvas]. It aims to serve a similar purpose as [gfx][gfx], but provide an introduction to using C and WASM. Wefx is meant to be a teaching / learning tool for C and graphics. Wefx is not using OpenGL /
4-
WebGL or anything like that. It is doing very basic pixel manipulation and
5-
has very simple functions to draw pixels and lines.
3+
Wefx is a simple graphics library for drawing using C11, WASM
4+
([Web Assembly][webassembly]), and an [HTML canvas][htmlcanvas].
5+
It aims to serve a similar purpose as [gfx][gfx], but provide an introduction
6+
to using C and WASM. Wefx is meant to be a teaching / learning tool for C and
7+
graphics. Wefx is not using OpenGL / WebGL or anything like that. It is doing
8+
very basic pixel manipulation and has very simple functions to draw pixels and
9+
lines.
610

7-
You can also [download the documentation](https://raw.githubusercontent.com/robrohan/wefx/main/docs/manual.pdf)
11+
You can also download the
12+
[documentation](https://raw.githubusercontent.com/robrohan/wefx/main/docs/manual.pdf)
813

9-
![Example Screenshot](https://raw.githubusercontent.com/robrohan/wefx/main/docs/wefx_shot.png)
14+
![Screenshot](https://raw.githubusercontent.com/robrohan/wefx/main/docs/wefx_shot.png)
1015

1116
## Quick Start
1217

13-
If you are using Ubuntu, you can run `make init` to install the correct version of clang and tools. If you are on another system, you will have to install `clang` yourself.
18+
If you are using Ubuntu, you can run `make init` to install the correct
19+
version of clang and tools. If you are on another system, you will have to
20+
install `clang` yourself.
1421

15-
Once installed, `make build` should compile `examples/example0.c` into WASM (if there are no errors). If successful, and if you have python installed, you can run `make serve` to start a simple HTTP server and browse to http://localhost:8000 to view wasm output.
22+
Once installed, `make build` should compile `examples/example0.c` into WASM
23+
(if there are no errors). If successful, and if you have python installed, you
24+
can run `make serve` to start a simple HTTP server and browse to
25+
http://localhost:8000 to view wasm output.
1626

1727
## Using The Project
1828

@@ -41,8 +51,9 @@ You'll need the following programs installed:
4151
- make (optional - MacOS and Linux)
4252
- (optional) python3
4353

44-
On MacOS or Linux these tools should be available already, or easily
45-
installed with homebrew (`brew install`), or Apt (`apt install`), or your local package manager.
54+
On MacOS or Linux these tools should be available already, or easily installed
55+
with homebrew (`brew install`), or Apt (`apt install`), or your local package
56+
manager.
4657

4758
### Compiling
4859

@@ -71,7 +82,9 @@ directly from your file system (this is just how wasm loading works).
7182
If you try to open the `index.html` file directly you will get an error
7283
like:
7384

74-
> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///xxxxx/build/wefx.wasm. (Reason: CORS request not http).
85+
> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the
86+
> remote resource at file:///xxxxx/build/wefx.wasm. (Reason: CORS request not
87+
> http).
7588
7689
A basic http server comes with python3, and the make file will run that
7790
server if you run:
@@ -91,9 +104,9 @@ to see the compiled code.
91104
---
92105

93106
If you already have a favorite server (for example I use
94-
[busboy](https://github.com/robrohan/busboy)), you can use that serve to
95-
serve the `build` directory instead, and then run the `make build` command
96-
to replace the wasm file as you play around.
107+
[busboy](https://github.com/robrohan/busboy)), you can use that serve to serve
108+
the `build` directory instead, and then run the `make build` command to replace
109+
the wasm file as you play around.
97110

98111
For example in one shell I run:
99112

@@ -112,15 +125,16 @@ And then simply refresh the browser to see changes.
112125
### Writing Code
113126

114127
If just teaching / learning about graphics, you'll only need to edit the
115-
[./examples/example0.c](./examples/example0.c) file. There are two entry
116-
points into that file:
128+
[./examples/example0.c](./examples/example0.c) file. There are two entry points
129+
into that file:
117130

118131
| Function | Usage |
119132
| ---------| -----|
120133
|init()| Called once at the start of the app|
121134
|main_loop(time)| Called every frame with time being time since app start|
122135

123-
You can also add your own entry files in the examples directory, and then pass them to the build script using the _MAIN_ variable. For example:
136+
You can also add your own entry files in the examples directory, and then pass
137+
them to the build script using the _MAIN_ variable. For example:
124138

125139
```{sh}
126140
make build MAIN=examples/example1.c
@@ -132,7 +146,8 @@ This will build the WASM file using `example1.c` as the entry point.
132146

133147
#### API
134148

135-
The API calls try to emulate [gfx][gfx] as much as possible. Here are a few currently supported functions (see the documentation for a full reference):
149+
The API calls try to emulate [gfx][gfx] as much as possible. Here are a few
150+
currently supported functions (see the documentation for a full reference):
136151

137152
| Function | Does |
138153
| ---------| -----|
@@ -145,7 +160,8 @@ The API calls try to emulate [gfx][gfx] as much as possible. Here are a few curr
145160

146161
#### Coordinate System
147162

148-
The coordinate system in newer versions has changed to reflect most other drawing styles. The system works thusly:
163+
The coordinate system in newer versions has changed to reflect most other
164+
drawing styles. The system works thusly:
149165

150166
```
151167
+Y

examples/example0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// Called once at startup
1414
// note: memory not initialized yet so 'print' will not work
15-
EXPORT int init()
15+
EXPORT int init(void)
1616
{
1717
// Open a "window"
1818
int err = wefx_open(W, H, "Logo Window");

examples/example1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define W 1024
66
#define H 768
77

8-
EXPORT int init()
8+
EXPORT int init(void)
99
{
1010
int err = wefx_open(W, H, "Test Window");
1111
if (err)

src/events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Similar to how _wefx\_open_ created screen memory, the _wefx_open_events_
2525
function allocates memory for the event queue.
2626
2727
*/
28-
wefx_event_queue *wefx_open_events()
28+
wefx_event_queue *wefx_open_events(void)
2929
{
3030
wefx_q = malloc(sizeof(struct wefx_event_queue));
3131
// wefx_q = &(const struct wefx_event_queue){ 0 };

src/events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct wefx_event_queue
4444

4545
//////////////////////////////////////////////
4646

47-
wefx_event_queue *wefx_open_events();
47+
wefx_event_queue *wefx_open_events(void);
4848

4949
void wefx_init_queue(wefx_event_queue *q);
5050

src/wefx.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ This is often called at the top of the render loop to reset to a blank slate bef
142142
doing any drawing.
143143
144144
*/
145-
void wefx_clear()
145+
void wefx_clear(void)
146146
{
147147
for (int q = 0; q < w * h; q++)
148148
buffer[q] = bg_color;
@@ -237,10 +237,10 @@ what it considers to be the screen.
237237
---
238238
239239
*/
240-
EXPORT void wefx_draw(unsigned int *screen)
240+
EXPORT void wefx_draw(unsigned int *iscreen)
241241
{
242242
for (int q = 0; q < w * h; q++)
243-
screen[q] = buffer[q];
243+
iscreen[q] = buffer[q];
244244
}
245245
/*
246246
@@ -251,11 +251,11 @@ size to be. These methods are exposed to Javascript to get the X
251251
and Y dimensions of the buffer / screen.
252252
253253
*/
254-
EXPORT int wefx_xsize()
254+
EXPORT int wefx_xsize(void)
255255
{
256256
return w;
257257
}
258-
EXPORT int wefx_ysize()
258+
EXPORT int wefx_ysize(void)
259259
{
260260
return h;
261261
}

src/wefx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void wefx_line(int x1, int y1, int x2, int y2);
1919
void wefx_color(unsigned int red, unsigned int green, unsigned int blue);
2020

2121
// Clear the graphics window to the background color.
22-
void wefx_clear();
22+
void wefx_clear(void);
2323

2424
// Change the current background color.
2525
void wefx_clear_color(unsigned int red, unsigned int green, unsigned int blue);
@@ -32,11 +32,11 @@ void wefx_clear_color(unsigned int red, unsigned int green, unsigned int blue);
3232
// int wefx_ypos();
3333

3434
// Return the X and Y dimensions of the window.
35-
int wefx_xsize();
36-
int wefx_ysize();
35+
int wefx_xsize(void);
36+
int wefx_ysize(void);
3737

3838
extern void print(const char *);
3939

4040
void wefx_draw(unsigned int *screen);
4141

42-
#endif // WEFX__H
42+
#endif // WEFX__H

0 commit comments

Comments
 (0)