Skip to content

Commit c80815d

Browse files
committed
meta: Enable -Wpedantic
I'd like to aim for POSIX C99 compatibility with this project. There are only two places where -Wpedantic was still warning about things. In sdl.c, it didn't like assigning (void *) to function pointers, but the whole dynamic sdl2 implementation depends on that, so I disabled the diagnostic for a small region in try_get_sdl2_syms() there. The rest were a few warnings in transforms.c, resolved by removing a few const qualifiers.
1 parent 4011ff3 commit c80815d

File tree

13 files changed

+25
-19
lines changed

13 files changed

+25
-19
lines changed

CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ if (MSVC)
3434
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
3535
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
3636
else()
37-
# set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wconversion -std=gnu99")
38-
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-missing-field-initializers -std=c99 -D_POSIX_C_SOURCE=200112L")
37+
set(CMAKE_C_FLAGS "-Wall -Wextra -Wpedantic -Wno-missing-field-initializers -std=c99 -D_POSIX_C_SOURCE=200112L")
3938
set(CMAKE_C_FLAGS_RELEASE "-O2 -ftree-vectorize -g")
4039
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
4140
if (ASAN)

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ MAKEFLAGS += --no-builtin-rules
22
CC?=cc
33
-include ccache.mk
44
OPT?=-O2
5-
CFLAGS=-I./include/ -I./src/ -Wall -Wextra -Wno-missing-field-initializers -std=c99 -D_POSIX_C_SOURCE=200112L $(OPT) -g -ftree-vectorize
5+
CFLAGS=-I./include/ -I./src/ -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -std=c99 -D_POSIX_C_SOURCE=200112L $(OPT) -g -ftree-vectorize
66
LDLIBS=-lpthread -lm -ldl
77

88
BINDIR=bin

src/common/logging.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void printPrefix(enum logType type) {
6464
}
6565
}
6666

67-
static void printDate() {
67+
static void printDate(void) {
6868
const time_t curTime = time(NULL);
6969
struct tm *time = localtime(&curTime);
7070
printf("[%d-%02d-%02d %02d:%02d:%02d] ",

src/common/platform/capabilities.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typedef unsigned short u_short;
2020
#include <unistd.h>
2121
#endif
2222

23-
int sys_get_cores() {
23+
int sys_get_cores(void) {
2424
#ifdef __APPLE__
2525
int nm[2];
2626
size_t len = 4;

src/common/platform/mutex.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "mutex.h"
1010
#include <stdlib.h>
1111

12-
struct cr_mutex *mutex_create() {
12+
struct cr_mutex *mutex_create(void) {
1313
struct cr_mutex *new = calloc(1, sizeof(*new));
1414
#ifdef WINDOWS
1515
InitializeCriticalSection(&new->lock);

src/common/transforms.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ struct transform tform_new_scale(float scale) {
184184
return transform;
185185
}
186186

187-
static void getCofactor(const float A[4][4], float cofactors[4][4], int p, int q, int n) {
187+
static void getCofactor(/*const*/ float A[4][4], float cofactors[4][4], int p, int q, int n) {
188188
int i = 0;
189189
int j = 0;
190190

@@ -203,7 +203,7 @@ static void getCofactor(const float A[4][4], float cofactors[4][4], int p, int q
203203

204204
//I really, really hope this is faster than the generic one
205205
//I wrote this by hand...
206-
float findDeterminant4x4(const float A[4][4]) {
206+
float findDeterminant4x4(/*const*/ float A[4][4]) {
207207
float topLeft = A[0][0] * ((A[1][1] * ((A[2][2]*A[3][3])-(A[2][3]*A[3][2]))) - (A[1][2] * ((A[2][1]*A[3][3])-(A[2][3]*A[3][1]))) + (A[1][3] * ((A[2][1]*A[3][2])-(A[2][2]*A[3][1]))));
208208
float topRigh = A[0][1] * ((A[1][0] * ((A[2][2]*A[3][3])-(A[2][3]*A[3][2]))) - (A[1][2] * ((A[2][0]*A[3][3])-(A[2][3]*A[3][0]))) + (A[1][3] * ((A[2][0]*A[3][2])-(A[2][2]*A[3][0]))));
209209
float botLeft = A[0][2] * ((A[1][0] * ((A[2][1]*A[3][3])-(A[2][3]*A[3][1]))) - (A[1][1] * ((A[2][0]*A[3][3])-(A[2][3]*A[3][0]))) + (A[1][3] * ((A[2][0]*A[3][1])-(A[2][1]*A[3][0]))));
@@ -212,7 +212,7 @@ float findDeterminant4x4(const float A[4][4]) {
212212
}
213213

214214
//Find det of a given 4x4 matrix A
215-
float findDeterminant(const float A[4][4], int n) {
215+
float findDeterminant(/*const*/ float A[4][4], int n) {
216216
float det = 0.0f;
217217

218218
if (n == 1)
@@ -230,7 +230,7 @@ float findDeterminant(const float A[4][4], int n) {
230230
return det;
231231
}
232232

233-
static void findAdjoint(const float A[4][4], float adjoint[4][4]) {
233+
static void findAdjoint(/*const*/ float A[4][4], float adjoint[4][4]) {
234234
int sign = 1;
235235
float temp[4][4];
236236

src/driver/sdl.c

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ static struct sdl_syms *try_get_sdl2_syms(void) {
7575
void *sdl2 = try_find_sdl2_lib();
7676
if (!sdl2) return NULL;
7777
struct sdl_syms *syms = calloc(1, sizeof(*syms));
78+
/*
79+
warning: ISO C forbids initialization between function pointer and ‘void *’ [-Wpedantic]
80+
=> We don't care about this in $CURRENT_YEAR :]
81+
*/
82+
#pragma GCC diagnostic ignored "-Wpedantic"
83+
#pragma GCC diagnostic push
7884
*syms = (struct sdl_syms){
7985
.lib = sdl2,
8086
.SDL_VideoInit = dyn_sym(sdl2, "SDL_VideoInit"),
@@ -99,6 +105,7 @@ static struct sdl_syms *try_get_sdl2_syms(void) {
99105
.SDL_UpdateTexture = dyn_sym(sdl2, "SDL_UpdateTexture"),
100106
.SDL_RenderCopy = dyn_sym(sdl2, "SDL_RenderCopy")
101107
};
108+
#pragma GCC diagnostic pop
102109
for (size_t i = 0; i < (sizeof(struct sdl_syms) / sizeof(void *)); ++i) {
103110
if (!((void **)syms)[i]) {
104111
logr(warning, "sdl_syms[%zu] is NULL\n", i);

src/lib/accelerators/bvh.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static inline struct bvh_index make_inner_index(size_t first_child) {
150150
};
151151
}
152152

153-
static inline struct split make_invalid_split() {
153+
static inline struct split make_invalid_split(void) {
154154
return (struct split) {
155155
.axis = -1,
156156
.pos = 0,
@@ -162,7 +162,7 @@ static inline bool is_valid_split(const struct split *split) {
162162
return split->axis <= 2;
163163
}
164164

165-
static inline struct bin make_empty_bin() {
165+
static inline struct bin make_empty_bin(void) {
166166
return (struct bin) {
167167
.bbox = emptyBBox,
168168
.count = 0

src/lib/api/c-ray.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939

4040
#define VERSION "0.6.3"DEBUG
4141

42-
char *cr_get_version() {
42+
char *cr_get_version(void) {
4343
return VERSION;
4444
}
4545

46-
char *cr_get_git_hash() {
46+
char *cr_get_git_hash(void) {
4747
return gitHash();
4848
}
4949

@@ -53,7 +53,7 @@ struct cr_shader_node *shader_deepcopy(const struct cr_shader_node *in);
5353

5454
struct cr_renderer;
5555

56-
struct cr_renderer *cr_new_renderer() {
56+
struct cr_renderer *cr_new_renderer(void) {
5757
return (struct cr_renderer *)renderer_new();
5858
}
5959

src/lib/protocol/server.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void client_drop(struct render_client *client) {
4747
client->status = Disconnected;
4848
}
4949

50-
static cJSON *make_handshake() {
50+
static cJSON *make_handshake(void) {
5151
cJSON *handshake = cJSON_CreateObject();
5252
cJSON_AddStringToObject(handshake, "action", "handshake");
5353
cJSON_AddStringToObject(handshake, "version", PROTO_VERSION);

src/lib/protocol/worker.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static cJSON *processCommand(int connectionSocket, cJSON *json, size_t thread_li
355355
ASSERT_NOT_REACHED();
356356
}
357357

358-
static void workerCleanup() {
358+
static void workerCleanup(void) {
359359
if (!g_worker_renderer) return;
360360
renderer_destroy(g_worker_renderer);
361361
g_worker_renderer = NULL;

src/lib/renderer/samplers/sampler.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct sampler {
2323
} sampler;
2424
};
2525

26-
struct sampler *newSampler() {
26+
struct sampler *newSampler(void) {
2727
return calloc(1, sizeof(struct sampler));
2828
}
2929

src/lib/vendored/pcg_basic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ uint32_t pcg32_random_r(pcg32_random_t* rng)
6767
return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
6868
}
6969

70-
uint32_t pcg32_random()
70+
uint32_t pcg32_random(void)
7171
{
7272
return pcg32_random_r(&pcg32_global);
7373
}

0 commit comments

Comments
 (0)