我正在查看 Linux 指南中函数 int brk() 的文档:
SYNOPSIS
#include <unistd.h>
int brk(void *addr);
void *sbrk(intptr_t increment);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
brk(), sbrk():
Since glibc 2.19:
_DEFAULT_SOURCE ||
(_XOPEN_SOURCE >= 500) &&
! (_POSIX_C_SOURCE >= 200112L)
From glibc 2.12 to 2.19:
_BSD_SOURCE || _SVID_SOURCE ||
(_XOPEN_SOURCE >= 500) &&
! (_POSIX_C_SOURCE >= 200112L)
Before glibc 2.12:
_BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
DESCRIPTION
brk() and sbrk() change the location of the program break, which
defines the end of the process's data segment (i.e., the program
break is the first location after the end of the uninitialized data
segment). Increasing the program break has the effect of allocating
memory to the process; decreasing the break deallocates memory.
brk() sets the end of the data segment to the value specified by
addr, when that value is reasonable, the system has enough memory,
and the process does not exceed its maximum data size (see
setrlimit(2)).
RETURN VALUE
On success, brk() returns zero. On error, -1 is returned, and errno
is set to ENOMEM.
还有一些我不明白的地方:如果 brk() 只将数据段的末尾设置为 addr 指定的值,那么为什么它的参数是 void* 而不是 int 类型?
谢谢您的帮助!