Hi,

I am only beginning to practice OpenCL, and am writing my first full program on my own. This is what I have so far.

Code :
#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>
 
main()
{
        cl_int error = 0;
        cl_platform_id platform;
        cl_context context;
        cl_command_queue queue;
        cl_device_id* device;
        cl_uint* num_devices;
 
        cl_int num_platforms;
        char platform_name[100];
 
        // Platform
        error = clGetPlatformIDs(1, &platform, &num_platforms);
        if(error != CL_SUCCESS) { printf("Error getting platform id\n"); return 0; }
        printf("The platform address is: %p\n", platform);
        printf("The number of platforms is: %d\n", num_platforms);
 
        error = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
        if(error != CL_SUCCESS) { printf("Error getting platform name\n"); return 0; }
        printf("The platform name is: %s\n", platform_name);
 
        device = malloc(sizeof(cl_device_id));
//      error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, device, num_devices);
        printf("Hello!\n");
        return 0;
}

The commented-out line,
Code :
error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, device, num_devices);
results in a segfault error. However, the strange thing is that it is not fatal, and the line "Hello!" prints just fine as per the printf statement. Does anyone know why the segfault is happening and how I can fix it? Thank you very much!