It seems that it is impossible to use typedef
and incorporate a malloc function in my program: More specifically:
groups.h
#include "headers.h"
#include "info.h"
#include "sub_list.h"
typedef struct group_entity *group;
group new_group(int id);
void free_group(group group);
groups.c
#include "groups.h"
struct group_entity {
int gId;
info gFirst;
info gLast;
subinfo gSub;
};
group new_group(int id) {
group new_group = malloc(sizeof(group));
if (!new_group) {
return NULL;
}
new_group->gId = id;
new_group->gFirst = NULL;
new_group->gLast = NULL;
new_group->gSub = NULL;
return new_group;
}
void free_group(group group) {
free(group);
}
header.h
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#define MG 5 /* Length of Groups Array. */
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stddef.h>
#include "headers.h"
#include "groups.h"
#include "info.h"
#include "sub_list.h"
int main() {
group new_object = new_group(5);
return 0;
}
Whenever I run this piece of code, I get halted with a breakpoint
exe_common.inl - ln 297.
if (!has_cctor)
_cexit();
I've tried using a free_group(group group)
function in my main.c - but it seems that I hit a breakpoint.
By using the VS 2019 debugger, I tried to find out which line causes the error. It seems that the breakpoint is caused AFTER my main is executed.
Quite curious behavior, since main won't even return 0
.