B[
Size: a a a
B[
AP
AM
AP
B[
AM
AM
#include <malloc.h>
#define MAX(x, y, type) (((type)x) > ((type)y) ? (x) : (y))
void *my_realloc(void *ptr, size_t size) {
void *new_ptr = NULL;
size_t old_size = _msize(ptr);
if (ptr == NULL)
return malloc(size);
else if (size && (new_ptr = malloc(MAX(size, old_size, size_t))))
memcpy(new_ptr, ptr, old_size);
if (old_size)
free(ptr);
return new_ptr;
}AM
AM
B[
AM
realloc() выделывался, то теперь будешь ловить NULL от malloc'аB[
CityCounter++;Почему при попытке расширить массив структур "City" CityList, после выполнения данного кода Citylіst cтает нулевым указателем?
CityList = realloc(CityList, (CityCounter + 1) * sizeof(City));
AM
AM
#include <malloc.h>
#define MAX(x, y, type) (((type)x) > ((type)y) ? (x) : (y))
void *my_realloc(void *ptr, size_t size) {
void *new_ptr = NULL;
size_t old_size = _msize(ptr);
if (ptr == NULL)
return malloc(size);
else if (size && (new_ptr = malloc(MAX(size, old_size, size_t))))
memcpy(new_ptr, ptr, old_size);
if (old_size)
free(ptr);
return new_ptr;
}B[
#include <malloc.h>
#define MAX(x, y, type) (((type)x) > ((type)y) ? (x) : (y))
void *my_realloc(void *ptr, size_t size) {
void *new_ptr = NULL;
size_t old_size = _msize(ptr);
if (ptr == NULL)
return malloc(size);
else if (size && (new_ptr = malloc(MAX(size, old_size, size_t))))
memcpy(new_ptr, ptr, old_size);
if (old_size)
free(ptr);
return new_ptr;
}B[
AM