Language: C

#include <stdbool.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct counting_sort_t {
  uint32_t *counting_arr;
  size_t counting_arr_len;
};

static void free_counting_sort_object(counting_sort_t c)
{
  if (c != NULL) {
    free(c->counting_arr);
  }
  free(c);
}

counting_sort_t counting_sort_create(size_t n)
{
  counting_sort_t c = (counting_sort_t)malloc(sizeof(counting_sort_t));
  if (c == NULL) goto err;

  c->counting_arr_len = n;
  c->counting_arr = (uint32_t *)calloc(sizeof(uint32_t), n);
  if (c->counting_arr == NULL) goto err;

  return c;

err:
  free_counting_sort_object(c);
  perror("malloc error");
  exit(1);
}

void counting_sort_destroy(counting_sort_t c)
{
  free_counting_sort_object(c);
}

static void count_incidence(counting_sort_t c, uint64_t data[], size_t len)
{
  uint32_t i;
  for (i = 0; i < len; i++) {
    c->counting_arr[data[i]]++;
  }
}

static void calc_cumulative_sum(counting_sort_t c)
{
  uint32_t i;
  for (i = 1; i < c->counting_arr_len; i++) {
    c->counting_arr[i] += c->counting_arr[i - 1];
  }
}

static bool copy_array(uint64_t data[], size_t len, uint64_t **p)
{
  *p = (uint64_t *)malloc(sizeof(data[0]) * len);
  if (*p == NULL) return false;

  memcpy(*p, data, sizeof(data[0]) * len);

  return true;
}

void counting_sort(counting_sort_t c, uint64_t data[], size_t len)
{
  count_incidence(c, data, len);

  calc_cumulative_sum(c);

  uint64_t *aux;
  if (!copy_array(data, len, &aux)) goto err;

  int32_t i;
  for (i = len - 1; 0 <= i; i--) {
    uint32_t index = c->counting_arr[aux[i]];
    data[index - 1] = aux[i];
    c->counting_arr[aux[i]]--;
  }

  return;
err:
  counting_sort_destroy(c);
  perror("malloc error");
  exit(1);
}

#if !defined(TEST)
uint64_t data[2000000];
int32_t main(void)
{
  int32_t num;
  scanf("%d", &num);

  counting_sort_t c = counting_sort_create(10001);

  int32_t i;
  for (i = 0; i < num; i++) {
    uint64_t val;
    scanf("%ld", &val);
    data[i] = val;
  }

  counting_sort(c, data, num);

  for (i = 0; i < num; i++) {
    if (i != 0) printf(" ");
    printf("%lu", data[i]);
  }
  printf("\n");

  counting_sort_destroy(c);

  return 0;
}
#endif

Compiler output:
main.c:13:39: error: unknown type name 'counting_sort_t'
   13 | static void free_counting_sort_object(counting_sort_t c)
      |                                       ^~~~~~~~~~~~~~~
main.c:21:1: error: unknown type name 'counting_sort_t'; use 'struct' keyword to refer to the type
   21 | counting_sort_t counting_sort_create(size_t n)
      | ^~~~~~~~~~~~~~~
      | struct 
main.c: In function 'counting_sort_create':
main.c:23:3: error: unknown type name 'counting_sort_t'; use 'struct' keyword to refer to the type
   23 |   counting_sort_t c = (counting_sort_t)malloc(sizeof(counting_sort_t));
      |   ^~~~~~~~~~~~~~~
      |   struct 
main.c:23:24: error: 'counting_sort_t' undeclared (first use in this function)
   23 |   counting_sort_t c = (counting_sort_t)malloc(sizeof(counting_sort_t));
      |                        ^~~~~~~~~~~~~~~
main.c:23:24: note: each undeclared identifier is reported only once for each function it appears in
main.c:23:40: error: expected ',' or ';' before 'malloc'
   23 |   counting_sort_t c = (counting_sort_t)malloc(sizeof(counting_sort_t));
      |                                        ^~~~~~
main.c:24:9: warning: comparison between pointer and integer
   24 |   if (c == NULL) goto err;
      |         ^~
main.c:26:4: error: invalid type argument of '->' (have 'int')
   26 |   c->counting_arr_len = n;
      |    ^~
main.c:27:4: error: invalid type argument of '->' (have 'int')
   27 |   c->counting_arr = (uint32_t *)calloc(sizeof(uint32_t), n);
      |    ^~
main.c:28:8: error: invalid type argument of '->' (have 'int')
   28 |   if (c->counting_arr == NULL) goto err;
      |        ^~
main.c:33:3: error: implicit declaration of function 'free_counting_sort_object' [-Wimplicit-function-declaration]
   33 |   free_counting_sort_object(c);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
main.c: At top level:
main.c:38:28: error: unknown type name 'counting_sort_t'
   38 | void counting_sort_destroy(counting_sort_t c)
      |                            ^~~~~~~~~~~~~~~
main.c:43:29: error: unknown type name 'counting_sort_t'
   43 | static void count_incidence(counting_sort_t c, uint64_t data[], size_t len)
      |                             ^~~~~~~~~~~~~~~
main.c:51:33: error: unknown type name 'counting_sort_t'
   51 | static void calc_cumulative_sum(counting_sort_t c)
      |                                 ^~~~~~~~~~~~~~~
main.c:69:20: error: unknown type name 'counting_sort_t'
   69 | void counting_sort(counting_sort_t c, uint64_t data[], size_t len)
      |                    ^~~~~~~~~~~~~~~
main.c: In function 'main':
main.c:99:3: error: unknown type name 'counting_sort_t'; use 'struct' keyword to refer to the type
   99 |   counting_sort_t c = counting_sort_create(10001);
      |   ^~~~~~~~~~~~~~~
      |   struct 
main.c:108:3: error: implicit declaration of function 'counting_sort'; did you mean 'counting_sort_create'? [-Wimplicit-function-declaration]
  108 |   counting_sort(c, data, num);
      |   ^~~~~~~~~~~~~
      |   counting_sort_create
main.c:116:3: error: implicit declaration of function 'counting_sort_destroy'; did you mean 'counting_sort_create'? [-Wimplicit-function-declaration]
  116 |   counting_sort_destroy(c);
      |   ^~~~~~~~~~~~~~~~~~~~~
      |   counting_sort_create