Peter N Peter N - 6 months ago 27
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 {