- 主题:这个static有什么作用?
static inline void encode_base64(char dest[static 4], const uint8_t src[stat
ic 3]) {...}
这个函数参数中的 static 4 感觉好奇怪,印象中没有见过这么用的,这里的static啥
作用?
--
修改:gameplayer FROM 222.128.5.*
FROM 222.128.5.*
常见,表明这个函数只在这个.c文件里定义和使用。
如果别的.c文件里有同名函数,则互不干扰。
【 在 gameplayer (*.*) 的大作中提到: 】
: static inline void encode_base64(char dest[static 4], const uint8_t src[stat
: ic 3]) {...}
:
: 这个函数参数中的 static 4 感觉好奇怪,印象中没有见过这么用的,这里的static啥
--
FROM 124.217.189.*
不是开头那个static,是函数参数中的 char dest[static 4],这里的static
【 在 fanci 的大作中提到: 】
: 常见,表明这个函数只在这个.c文件里定义和使用。
: 如果别的.c文件里有同名函数,则互不干扰。
--
修改:gameplayer FROM 222.128.5.*
FROM 222.128.5.*
没见过 :(
搜了一下
A declaration of a parameter as ''array of type'' shall be adjusted to
''qualified pointer to type'', where the type qualifiers (if any) are those
specified within the [ and ] of the array type derivation. If the keyword
static also appears within the [ and ] of the array type derivation, then for
each call to the function, the value of the corresponding actual argument
shall provide access to the first element of an array with at least as many
elements as specified by the size expression.
然后stackoverflow有详细解释
https://stackoverflow.com/questions/18362315/static-size-of-array-in-c99
【 在 gameplayer 的大作中提到: 】
: static inline void encode_base64(char dest[static 4], const uint8_t src[stat
: ic 3]) {...}
: 这个函数参数中的 static 4 感觉好奇怪,印象中没有见过这么用的,这里的static啥
: ...................
--
修改:haha103 FROM 182.150.115.*
FROM 182.150.115.*
C11标准文本自己就有个例子
void f(double (* restrict a)[5]);
void f(double a[restrict][5]);
void f(double a[restrict 3][5]);
void f(double a[restrict static 3][5]);
(Note that the last declaration also specifies that the argument corresponding to a in any call to f must be a non-null pointer to the first of at least three arrays of 5 doubles, which the others do not.)
【 在 haha103 的大作中提到: 】
: 没见过 :(
: 搜了一下
: A declaration of a parameter as ''array of type'' shall be adjusted to
: ...................
--
FROM 121.32.155.*
3Q! 原来就是个提示,告诉调用者参数的要求,不符合时编译器也会有警告
It tells the user of the function that they must provide an array of at
least 5 elements (and if they do not, they will invoke undefined behaviour).
It tells the optimizer that it may assume a non-null pointer to an array
of at least 5 elements and it may optimize accordingly.
【 在 haha103 的大作中提到: 】
: 没见过 :(
: 搜了一下
: A declaration of a parameter as ''array of type'' shall be adjusted to
: ...................
--
修改:gameplayer FROM 222.128.5.*
FROM 222.128.5.*