Category : malloc

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <locale.h> #include <time.h> #include <iostream> typedef struct No{ int telefone; char nome[50]; struct No *proximo; }No; typedef struct{ No *inicio; int tam; }Lista; //inserção no inicio da lista inserirInicio(Lista *lista, int telefone, char nome){ No *novo = (No*)malloc(sizeof(No)); novo->telefone = telefone; novo->nome = nome; novo->proximo = lista->inicio; lista->inicio ..

Read more

I am trying to write some tests in Catch2 (a C++ library) for a simple C library example and I am a little confused about how to initialize a C struct. My C header looks like this: struct node; And my C implementation cannot be simpler: struct node { int num; struct node* next; } ..

Read more

I implemented a custom operator new to track allocation behaviour. It allocates 8 bytes more than requested to prepend the allocated size as std::size_t. void *operator new(std::size_t count) { auto *pBase = reinterpret_cast<std::size_t*>(std::malloc(count + sizeof(std::size_t))); pBase[0] = count; auto *pUserMem = reinterpret_cast<std::byte*>(pBase) + sizeof(std::size_t); return reinterpret_cast<void*>(pUserMem); } Additionally I reimplemented operator delete to (in a ..

Read more