我有#include<math.h>,我试图使用pow(x,y)和powf(x,y).但似乎它们都不符合c99标准.我用命令gcc -std=c99 test.c -o test编译.我可以使用什么功能?
我正在Xcode 4中创建一个非常基本的C控制台应用程序,我在编译时遇到警告:Implicit declaration of memcmp is invalid in c99.
我对函数的使用正如您所期望的那样:
if(memcmp(buf, block, 0x14) != 0)
{
fclose(fh);
printf("invalid file: %s\n", argv[argc-1]);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
如何使用该功能错误,我该如何解决?
我知道C99允许声明与代码混合,而不仅仅是在开头,但我试图在ISO/IEC 9899:1999中找到它的位置 - 你能指出我应该搜索的部分吗?
提前致谢.
当我在我的头文件中声明函数原型时,即使我从不使用'extern'关键字,我仍可以访问程序中的所有位置.它们仅对静态库很重要,或者何时需要它?
该陈述a[i]=i++;未定义,因为存在一个混淆,即i(旧的或新的)用于评估左侧的值(旧的或新的)L-value.如果使用编译器,此编译器会为此语句提供警告(操作..可能未定义)-Wall.
在下面的代码中,语句x->a = x->b, ++x++->b;
x正在更改,在左侧,它用于获取L-value.对于此语句,编译器在执行时不会发出任何警告-Wall.
有人可以解释为什么这不是未定义的行为?谢谢!
struct Data {
int a;
int b;
} y[4] = { 10, 20, 30, 40};
struct Data *x = y;
int i;
for(i=0; i<2; i++) {
x->a = x->b, ++x++->b;
printf("%d %d\t", y[i].a, y[i].b);
}
Run Code Online (Sandbox Code Playgroud) 在测试代码
#include <stdio.h>
int main()
{
char a[5][3];
printf("a = %p\n", a);
printf("&a[0] = %p\n", &a[0][0]);
printf("&a = %p\n", &a);
printf("*a = %p\n", *a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它被编译并以C模式给出输出(http://ideone.com/KD9Wz1):
a = 0xbfd8ea51
&a[0] = 0xbfd8ea51
&a = 0xbfd8ea51
*a = 0xbfd8ea51
Run Code Online (Sandbox Code Playgroud)
在使用严格的C99模式(http://ideone.com/iTACGZ)进行编译时,会导致编译错误:
prog.c: In function ‘main’:
prog.c:7:10: error: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘char (*)[3]’ [-Werror=format]
prog.c:9:10: error: format ‘%p’ expects argument of type ‘void *’, but argument 2 …Run Code Online (Sandbox Code Playgroud) 我不太了解5.1.2.3/3的以下部分:
实际实现不需要评估表达式的一部分,如果它可以推断出它的值未被使用并且不产生所需的副作用(包括由调用函数或访问易失性对象引起的任何副作用).
假设我有以下代码:
char data[size];
int i;
int found;
/* initialize data to some values in here */
found = 0;
for( i = 0; i < size; i++ ) {
if( data[i] == 0 ) {
found = 1;
/* no break in here */
}
}
/* i no longer used, do something with "found" here */
Run Code Online (Sandbox Code Playgroud)
请注意,found以&开头0可以保持不变或变为1.它不能变成1然后变成别的东西.因此,以下代码将产生相同的结果(除了i在循环之后未使用的值):
char data[size];
int i;
int found;
/* initialize data to …Run Code Online (Sandbox Code Playgroud) C编程语言的C99标准将_Bool数据类型定义为另一种数据类型的宏(因为该语言无法处理类型安全布尔值).
是_Bool为宏unsigned char,unsigned int或其他一些数据类型?
一切都在标题中,我进行了很多搜索,但找不到使用我的编译器的标准是C89 C90 C99还是C11 ...我的意思是当我们不指定-std选项(默认选项)时?
为什么int16_t complex不在int16_tx86和x86_64机器上编译,是否为typedef short int?以下是使用gcc 5.4和4.9测试的示例代码,其中包含C99和C11标准.编译器抱怨在声明说明符中有两个或更多数据类型.
码:
#include <complex.h>
#include <stdint.h>
#include <stdio.h>
int main()
{
float complex x = I + I / 3 * I / 2;
short int complex y = I + I / 3 * I / 2;
int16_t complex z = I + I / 3 * I / 2; /* Why ? */
printf("x=(%+f,%+f)\n", creal(x), cimag(x));
printf("y=(%+f,%+f)\n", creal(y), cimag(y));
printf("z=(%+f,%+f)\n", creal(z), cimag(z)); /* Why ? */
return 0;
} …Run Code Online (Sandbox Code Playgroud)