在我的代码中,我使用变量PATH_MAX作为缓冲区大小。当我包括应该定义#include <limits.h>的库时,我遇到了一个问题。当我使用这个库时,我的IDE不承认变量是已定义的,但是当我包含像#include <linux/limits.h>这样的库时,就没有问题了,变量就是define。我的问题是,两者之间有什么区别,当我交叉编译我的项目时会不会引起问题?
谢谢大家的回答!
发布于 2022-07-29 16:29:29
H标头是所有实现都需要提供的标准报头。这包括数值限制,如INT_MIN和INT_MAX等。PATH_MAX不是此文件的一部分。
H头是特定于Linux的。正是在这里定义了PATH_MAX。
发布于 2022-07-29 16:37:25
H是一个非常小的头文件:
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _LINUX_LIMITS_H
#define _LINUX_LIMITS_H
#define NR_OPEN 1024
#define NGROUPS_MAX 65536 /* supplemental group IDs are available */
#define ARG_MAX 131072 /* # bytes of args + environ for exec() */
#define LINK_MAX 127 /* # links a file may have */
#define MAX_CANON 255 /* size of the canonical input queue */
#define MAX_INPUT 255 /* size of the type-ahead buffer */
#define NAME_MAX 255 /* # chars in a file name */
#define PATH_MAX 4096 /* # chars in a path name including nul */
#define PIPE_BUF 4096 /* # bytes in atomic write to a pipe */
#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
#define RTSIG_MAX 32
#endif这个文件在Linux中定义了PATH_MAX。
limits.h是定义语言(而不是系统)相关宏的C标准标头。
https://stackoverflow.com/questions/73168335
复制相似问题