小编Jee*_*tel的帖子

如何计算指针指向内存的大小?

在我写的一个函数中:

char *ab; 

ab=malloc(10);
Run Code Online (Sandbox Code Playgroud)

然后在另一个函数中我想知道ab指针指向的内存大小.有什么方法我可以知道ab指向10个内存的字符?

c memory-management

7
推荐指数
2
解决办法
6270
查看次数

静态功能有什么优势?

在一个项目源代码中看到我见过下面的声明

static int *foo();
Run Code Online (Sandbox Code Playgroud)

所以它将foo声明为返回指向int的指针的静态函数.所以我在这里问你是什么意思将函数声明为静态?

c static

7
推荐指数
2
解决办法
6873
查看次数

使用Linux中的CLI更改文件夹中的所有文件扩展名

如何在Linux中使用CLI上的一个命令更改文件夹中的所有文件扩展名?

linux shell

7
推荐指数
2
解决办法
6634
查看次数

有没有办法在小端pc上编译和运行程序作为big-endian?

现在我已经为大端编写了一个程序,我没有大端机,但我想检查我的程序是否能正常工作在大端,所以我怎样才能在我的小端pc上查看.

有没有在线虚拟大端编译器?

注意:我已经用谷歌搜索了这个,但没有得到任何东西.

c linux memory endianness

6
推荐指数
1
解决办法
1501
查看次数

函数定义在另一个函数定义中:它有效吗?

看到这段代码

#include<stdio.h>

int main()
{
    void test(void)
    {
        printf("test");
        return;
    }
printf("main");
return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个男女同校工作正常,并没有给出任何警告和错误.我不知道为什么会这样?这里我在其他函数定义中写了一个函数定义,所以它有效吗?

编辑:如果是,那么有任何用途吗?

为什么gcc需要添加这个功能作为扩展..这应该是任何用途吗?不是吗?!

c function

6
推荐指数
1
解决办法
1万
查看次数

如何在const char字符串中转换uint64_t值?

在一种情况下看

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)

我怎样才能做到这一点?

c

6
推荐指数
2
解决办法
1万
查看次数

如何使用"指向数组10的int"?

我有以下代码:

#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?


编辑: …

c

6
推荐指数
2
解决办法
9974
查看次数

Linux驱动程序中的platform_get_resource是什么?

有人可以解释为什么以及如何使用platform_get_resource功能?

我已经看到IORESOURCE_MEM在许多地方使用,比如这里的第二个参数,这是什么意思?

我已经浏览了下面的链接,但无法得到正确的解释.

linux resources linux-kernel

6
推荐指数
1
解决办法
1万
查看次数

C中的位域内存管理

为了理解位字段存储器,我在下面创建了测试程序.

#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 linux memory

6
推荐指数
1
解决办法
469
查看次数

理解C编程语法

我遇到了这种语法,我无法知道如何开始理解这一点.

如何开始解码这样的c编程代码.

(*(void(*)())0)();
Run Code Online (Sandbox Code Playgroud)

我试图编译此代码,它编译时没有任何警告或错误.所以它似乎是c编程的有效语法.

c

6
推荐指数
1
解决办法
117
查看次数