1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-15 06:20:32 +02:00

Update C manual memory management example (#902)

In C (as opposed to C++) the explicit cast from void* to int* is not required. It is also not idiomatic to do so in C code.

Actual C codebase would use `malloc()` without the cast, and a C++ one (when not using abstractions) a `new int[n]` - both a bit cleaner and less verbose than this example.
This commit is contained in:
Wojtek Marczenko 2023-07-05 15:37:07 +02:00 committed by GitHub
parent d27daceda2
commit 4413b6a28f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ You must call `free` on every pointer you allocate with `malloc`:
```c
void foo(size_t n) {
int* int_array = (int*)malloc(n * sizeof(int));
int* int_array = malloc(n * sizeof(int));
//
// ... lots of code
//