1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include <pointer.cvh>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 |
|
|---|
| 4 | /* An example shows how $pointer_realloc works. */
|
|---|
| 5 | int main() {
|
|---|
| 6 | int * p = (int *)malloc(sizeof(int) * 10);
|
|---|
| 7 |
|
|---|
| 8 | p[2] = 4;
|
|---|
| 9 |
|
|---|
| 10 | $pointer_realloc(p, sizeof(int) * 12);
|
|---|
| 11 |
|
|---|
| 12 | p[10] = 3;
|
|---|
| 13 | $assert(p[2] == 4 && p[10] == 3);
|
|---|
| 14 | $pointer_realloc(p, sizeof(int) * 4);
|
|---|
| 15 | $assert(p[2] == 4);
|
|---|
| 16 | #ifdef BAD
|
|---|
| 17 | $assert(p[10] == 3);
|
|---|
| 18 | #endif
|
|---|
| 19 | free(p);
|
|---|
| 20 | return 0;
|
|---|
| 21 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.