From 6cbb5f421ef6be7b78ca60263a320aecf260b5c2 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 12 Sep 2017 09:28:10 +0100 Subject: [PATCH] Explicit casts to shut g++ warnings and errors --- opencl/common.h | 8 ++++---- opencl/interactive/vec_io.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/opencl/common.h b/opencl/common.h index 27d52a5..be8989e 100644 --- a/opencl/common.h +++ b/opencl/common.h @@ -37,7 +37,7 @@ char* common_read_file(const char *path, long *length_out) { fseek(f, 0, SEEK_END); length = ftell(f); fseek(f, 0, SEEK_SET); - buffer = malloc(length); + buffer = (char *)malloc(length); if (fread(buffer, 1, length, f) < (size_t)length) { return NULL; } @@ -52,7 +52,7 @@ char* common_read_file_null(const char *path) { char *f; long length; f = common_read_file(path, &length); - f = realloc(f, length + 1); + f = (char *)realloc(f, length + 1); f[length] = '\0'; return f; } @@ -68,7 +68,7 @@ void common_build_program( ret = clBuildProgram(*program, 1, &(common->device), options, NULL, NULL); if (CL_SUCCESS != ret) { clGetProgramBuildInfo(*program, common->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &err_len); - err = malloc(err_len); + err = (char *)malloc(err_len); clGetProgramBuildInfo(*program, common->device, CL_PROGRAM_BUILD_LOG, err_len, err, NULL); fprintf(stderr, "error: clBuildProgram:\n%s\n", err); free(err); @@ -195,7 +195,7 @@ void common_create_kernel_or_use_cache( } else { common_init_file(common, source_path); clGetProgramInfo(common->program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &binary_size, NULL); - binary = malloc(binary_size); + binary = (char *)malloc(binary_size); clGetProgramInfo(common->program, CL_PROGRAM_BINARIES, binary_size, &binary, NULL); f = fopen(bin_path, "w"); fwrite(binary, binary_size, 1, f); diff --git a/opencl/interactive/vec_io.c b/opencl/interactive/vec_io.c index 9b33a85..50b15a9 100644 --- a/opencl/interactive/vec_io.c +++ b/opencl/interactive/vec_io.c @@ -94,7 +94,7 @@ int main(int argc, char **argv) { if (argc > a) { source_path = argv[a]; } else { - source_path = "vec_io.cl"; + source_path = (char *)"vec_io.cl"; } a++; if (argc > a) { @@ -106,13 +106,13 @@ int main(int argc, char **argv) { /* Initialize data. */ n = 0; nmax = n + 1; - io = malloc(nmax * sizeof(*io)); + io = (cl_float *)malloc(nmax * sizeof(*io)); while(fscanf(input_vector_file, "%f", &f) != EOF) { io[n] = f; n++; if (n == nmax) { nmax *= 2; - io = realloc(io, nmax * sizeof(*io)); + io = (cl_float *)realloc(io, nmax * sizeof(*io)); } } io_sizeof = n * sizeof(*io); @@ -121,7 +121,7 @@ int main(int argc, char **argv) { } /* Create kernel. */ - common_create_kernel_or_use_cache(&common, use_cache, source_path, __FILE__ ".bin.tmp"); + common_create_kernel_or_use_cache(&common, use_cache, source_path, (char *)(__FILE__ ".bin.tmp")); buffer = clCreateBuffer(common.context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, io_sizeof, io, NULL); clSetKernelArg(common.kernel, 0, sizeof(buffer), &buffer); clEnqueueNDRangeKernel(common.command_queue, common.kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL);