You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-26 18:51:00 +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:
@ -10,7 +10,7 @@ You must call `free` on every pointer you allocate with `malloc`:
|
|||||||
|
|
||||||
```c
|
```c
|
||||||
void foo(size_t n) {
|
void foo(size_t n) {
|
||||||
int* int_array = (int*)malloc(n * sizeof(int));
|
int* int_array = malloc(n * sizeof(int));
|
||||||
//
|
//
|
||||||
// ... lots of code
|
// ... lots of code
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user