Tag: 声明

#ifdef(或其他预处理器指令)是否适用于函数声明(以测试函数存在性)?

为什么以下代码不能按预期工作? void foobar(int); #ifndef foobar printf(“foobar exists”); #endif 它总是打印信息; 它显然无法检测到一个函数作为一个实体的存在。 (这是一个过载的问题吗?) 为什么#ifdef (或其变体)不能检测函数声明? 声明应该在预处理时可用,所以它应该有效,不应该吗? 如果没有,是否有替代方案或解决方法?

在c标准库中定义了stdin?

我在stdio.h中找到了这一行: extern struct _IO_FILE *stdin; 基于这个’extern’关键字,我认为这只是一个声明。 我想知道stdin在哪里定义和初始化?

混合声明和代码

当我使用“gcc -o dene -Wall -ansi -pedantic-errors dene.c”编译函数时,gcc不会发出任何错误。(你可以看一下以char开头的行,在if循环中) static void remove_negation(char *s,char *s1) { char **cmainp=malloc(sizeof(char*)*1); int len=0;int d=0; int i=0; cmainp[0]=malloc(sizeof(char)*300); len=strlen(s); for(i=0;i<len;++i) { if(s[i]=='-') if(i==0 || s[i-1]==',') /*look*/ {char *p=malloc(sizeof(char)*3); /*look*/ ++i; p[0]=s[i]; p[1]='\0'; strcat(s1,","); strcat(s1,p); free(p); continue; } cmainp[0][d]=s[i]; ++d; } cmainp[0][d+1]='\0'; strcpy(cmainp[0],s); free(cmainp[0]); } 但是,当编译上面的函数用gcc重新格式化时,gcc会发出该错误; “dene.c:10:错误:ISO C90禁止混合声明和代码” static void remove_negation(char *s,char *s1) […]

在C中为数组分配多个值

有没有办法以浓缩forms这样做? GLfloat coordinates[8]; … coordinates[0] = 1.0f; coordinates[1] = 0.0f; coordinates[2] = 1.0f; coordinates[3] = 1.0f; coordinates[4] = 0.0f; coordinates[5] = 1.0f; coordinates[6] = 0.0f; coordinates[7] = 0.0f; return coordinates; 像coordinates = {1.0f, …}; ?

外部声明,T * v / s T

我在遗留项目中看到了以下代码片段。 /* token.c */ struct token id_tokens[MAX_TOKENS]; /* analyse.c (v1) */ extern struct token *id_tokens; /* Raised my eyebrow, id_token declares a pointer */ 我坚持要更改analyse.c以包含如下声明: /* analyse.c (v2) */ extern struct token id_tokens[]; /* I am happy with this. id_tokens declares array of unspecified size. */ 我想要v2因为pointer to T array of T 。 我朋友的反驳说,两者的行为都是一样的,所以我使用v1和v2并不重要。 问题1:不完整类型的数组是否耗尽指针? […]

在函数名称后声明函数参数

int func(x) int x; { …………. 这种宣言叫什么? 它何时有效/无效,包括C或C ++,某些标准修订和编译器?

如何自动将K&R函数声明转换为ANSI函数声明?

// K&R syntax int foo(a, p) int a; char *p; { return 0; } // ANSI syntax int foo(int a, char *p) { return 0; } 如您所见,在K&R样式中,变量的类型在新行中而不是在大括号中声明。 如何自动将K&R函数声明转换为ANSI函数声明? 在Linux中有人知道这么容易使用的工具吗?

搞清楚C声明

我对C很新,我想弄清楚一些C声明。 有人可以帮我解释这些C声明的含义吗? double (*b)[n]; double (*c[n])(); double (*d())[n]; 我很感激帮助!

指向指针和指向数组的指针之间的区别?

鉴于数组的名称实际上是指向数组的第一个元素的指针,以下代码: #include int main(void) { int a[3] = {0, 1, 2}; int *p; p = a; printf(“%d\n”, p[1]); return 0; } 按预期打印1 。 现在,鉴于我可以创建一个指向指针的指针,我写了以下内容: #include int main(void) { int *p0; int **p1; int (*p2)[3]; int a[3] = {0, 1, 2}; p0 = a; p1 = &a; p2 = &a; printf(“p0[1] = %d\n(*p1)[1] = %d\n(*p2)[1] = […]

将函数声明为“内联”的好处?

每当我读到C中的“内联”声明时,都会提到它只是编译器的一个提示 (即它不必遵守它)。 那么添加它有什么好处,还是我应该依赖编译器比我更了解?