Peter N Peter N - 2 months ago 10
C Question

'new' undeclared (first use in this function)

Why does this work in C++, but not in C? And what is the alternative for a C environment?

char *Buffer;
unsigned long Size;

Buffer = new char[Size]; // Throws an error in C, but not in C++


new and delete are not part of C. Please use malloc and free.

char *Buffer;
size_t Size = 100;
Buffer = malloc(Size);
if(Buffer == NULL) {
    puts("Bad allocation");
else {