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:
parent
d27daceda2
commit
4413b6a28f
@ -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
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user