在我写的一个函数中:
char *ab;
ab=malloc(10);
Run Code Online (Sandbox Code Playgroud)
然后在另一个函数中我想知道ab
指针指向的内存大小.有什么方法我可以知道ab
指向10个内存的字符?
在一个项目源代码中看到我见过下面的声明
static int *foo();
Run Code Online (Sandbox Code Playgroud)
所以它将foo声明为返回指向int的指针的静态函数.所以我在这里问你是什么意思将函数声明为静态?
现在我已经为大端编写了一个程序,我没有大端机,但我想检查我的程序是否能正常工作在大端,所以我怎样才能在我的小端pc上查看.
有没有在线虚拟大端编译器?
注意:我已经用谷歌搜索了这个,但没有得到任何东西.
看到这段代码
#include<stdio.h>
int main()
{
void test(void)
{
printf("test");
return;
}
printf("main");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个男女同校工作正常,并没有给出任何警告和错误.我不知道为什么会这样?这里我在其他函数定义中写了一个函数定义,所以它有效吗?
编辑:如果是,那么有任何用途吗?
为什么gcc需要添加这个功能作为扩展..这应该是任何用途吗?不是吗?!
在一种情况下看
uint64_t trackuid = 2906622092;
现在我想在函数参数所在的函数中传递此值 const char*
func(const char *uid)
{
printf("uid is %s",uid);
}
Run Code Online (Sandbox Code Playgroud)
这应该打印
uid is 2906622092
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有以下代码:
#include<stdio.h>
int main()
{
int(* a)[10]; //declare a as pointer to array 10 of int
int b[10]; // taken a array of 10 int
b[2]=32;
a=&b;
printf("b is on %p\n",&b);
printf("a is on %p\n",a);
printf("magic is %d\n",a[2]); // why this is not showing 32
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
b is on 0xbfa966d4
a is on 0xbfa966d4
magic is -1079417052
Run Code Online (Sandbox Code Playgroud)
在这里,我已采取a
的指针为int数组10,它指向数组b
,所以现在为什么我无法得到的32值a[2]
?
a[2]
被评估为*(a+2)
如此现在有一个数组的地址b
所以*(b+2)
并且*(a+2)
是相似的所以我为什么不在这里得到值32?
编辑: …
有人可以解释为什么以及如何使用platform_get_resource
功能?
我已经看到IORESOURCE_MEM
在许多地方使用,比如这里的第二个参数,这是什么意思?
我已经浏览了下面的链接,但无法得到正确的解释.
为了理解位字段存储器,我在下面创建了测试程序.
#include <stdio.h>
int main()
{
int a;
typedef struct {
int b7 : 1;
int b6 : 1;
int b5 : 1;
int b4 : 1;
int b3 : 1;
int b2 : 1;
int b1 : 1;
int b0 : 1;
} byte;
byte ab0 = {0,0,0,0,0,0,0,1};
a = *(int*)&ab0;
printf("ab0 is %x \n",a);
byte ab1 = {0,0,0,0,0,0,1,0};
a = *(int*)&ab1;
printf("ab1 is %x \n",a);
byte ab2 = {0,0,0,0,0,1,0,0};
a = *(int*)&ab2;
printf("ab2 is %x \n",a);
byte ab3 …
Run Code Online (Sandbox Code Playgroud) 我遇到了这种语法,我无法知道如何开始理解这一点.
如何开始解码这样的c编程代码.
(*(void(*)())0)();
Run Code Online (Sandbox Code Playgroud)
我试图编译此代码,它编译时没有任何警告或错误.所以它似乎是c编程的有效语法.
c ×8
linux ×4
memory ×2
endianness ×1
function ×1
linux-kernel ×1
resources ×1
shell ×1
static ×1