我将应用程序从Tru64移植到Linux,它使用limits.h中定义的PID_MAX.Linux没有那个定义.如何在不用手动阅读的情况下在c中找到PID_MAX /proc/sys/kernel/pid_max?有图书馆吗?
在Linux系统中(32位或64位),什么是大小pid_t,uid_t和gid_t?
一些背景:如果我想用于,例如,scanf()将字符串转换为标准整数类型,比如uint16_t,我将使用SCNu16from <inttypes.h>,如下所示:
#include <stdio.h>
#include <inttypes.h>
uint16_t x;
char *xs = "17";
sscanf(xs, "%" SCNu16, &x);
Run Code Online (Sandbox Code Playgroud)
但是一个更不常见的整数类型就像pid_t没有任何这样的东西; 只支持普通的整数类型<inttypes.h>.要转换的另一种方式,可移植printf()一个pid_t,我可以把它转换为intmax_t和使用PRIdMAX,就像这样:
#include <stdio.h>
#include <inttypes.h>
#include <sys/types.h>
pid_t x = 17;
printf("%" PRIdMAX, (intmax_t)x);
Run Code Online (Sandbox Code Playgroud)
然而,似乎没有办法可移植scanf()到一个pid_t.所以这是我的问题:如何便携地这样做?
#include <stdio.h>
#include <sys/types.h>
pid_t x;
char *xs = 17;
sscanf(xs, "%u", &x); /* Not portable! pid_t might not be int! /*
Run Code Online (Sandbox Code Playgroud)
我想到了scanf()一个 …
在C中是否有一个函数返回这样的变量的最大值(我将在下面的例子中命名函数"maxvalue")?
int a;
printf("%d", maxvalue(a)); // 32767
unsigned int b;
printf("%d", maxvalue(b)); // 65535
Run Code Online (Sandbox Code Playgroud)
所以基本上函数返回的值就像INT_MAX变量是有符号的INT,UINT_MAX是无符号的int等.