c99

On the practical advantage to C99's array size “guarantee” feature in function parameters?

谁说胖子不能爱 提交于 2020-08-04 14:34:21
问题 C99 introduced a new function argument notation where the static keyword can be used to specify that the argument has at least N elements. 6.7.6.3 Function declarators, p7 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,

On the practical advantage to C99's array size “guarantee” feature in function parameters?

匆匆过客 提交于 2020-08-04 14:32:31
问题 C99 introduced a new function argument notation where the static keyword can be used to specify that the argument has at least N elements. 6.7.6.3 Function declarators, p7 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,

On the practical advantage to C99's array size “guarantee” feature in function parameters?

≡放荡痞女 提交于 2020-08-04 14:32:28
问题 C99 introduced a new function argument notation where the static keyword can be used to specify that the argument has at least N elements. 6.7.6.3 Function declarators, p7 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,

C preprocessor tokenization does not expand macro?

对着背影说爱祢 提交于 2020-07-02 18:05:26
问题 1) Why is the macro MSG not expanded in the following expression? #define MSG Hello #define HELLO(name) MSG ## name void HELLO(Dave) () {} Using gcc -E -P test.cpp Output: void MSGDave () {} MSG name expands to Hello Dave . And MSG # name expands to Hello "Dave" . So what causes gcc not to expand MSG ## name ? 2) Is there a workaround? Is there a preprocessor directive like defined(x), such as expand(x)? 回答1: #define MSG Hello #define cat(x, y) x ## y #define cat2(x, y) cat(x, y) #define

Pass by reference in C99

人盡茶涼 提交于 2020-05-14 19:28:25
问题 I just read this: In C++ (and C99), we can pass by reference, which offers the same performance as a pointer-pass. So I tried this simple code: #include <stdio.h> void blabla(int& x){ x = 5; } int main(){ int y = 3; printf("y = %d\n", y); blabla(y); printf("y = %d\n", y); } The output was: gcc test.c -o test -std=c99 test.c:3:16: error: expected ';', ',' or ')' before '&' token test.c: In function 'main': test.c:10:2: warning: implicit declaration of function 'blabla' Now I'm confused. Is