小编Gee*_*kyJ的帖子

mmap系统调用中MAP_ANONYMOUS标志的用途是什么?

man页面,

MAP_ANONYMOUS
              The mapping is not backed by any file; its contents are initialized to zero.  The fd and offset arguments are ignored; however, some implementations  require
              fd  to  be  -1  if  MAP_ANONYMOUS  (or  MAP_ANON)  is  specified, and portable applications should ensure this.  The use of MAP_ANONYMOUS in conjunction with
              MAP_SHARED is only supported on Linux since kernel 2.4.
Run Code Online (Sandbox Code Playgroud)

使用目的是MAP_ANONYMOUS什么?任何一个例子都会很好.还要从哪里映射内存?

man页面上写的The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is only supported on Linux …

linux memory memory-management mmap system-calls

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

为什么在将main声明为`int main(void)`时传递命令行参数时没有错误?

情况1:

void hello(void) {
    //something
}

int main()
{
    hello(1); //error
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

案例2:

int main(void) {
    //something
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

执行:

./a.out something something //No error, Why?
Run Code Online (Sandbox Code Playgroud)

为什么没有错误?main将无法采取任何论点.那么为什么可以从命令行提供参数呢?

c program-entry-point command-line-arguments

14
推荐指数
3
解决办法
882
查看次数

什么是Linux内核上下文中的DMA映射和DMA引擎?

什么是Linux内核上下文中的DMA映射和DMA引擎?什么时候可以在Linux设备驱动程序中使用DMA映射API和DMA引擎API?任何真正的Linux设备驱动程序示例作为参考都会很棒.

linux linux-device-driver linux-kernel dma pci-e

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

为什么结构填充没有正确发生?

#include<stdio.h>

struct A
{
    char        c;
    double      e;
    int         s;
}A;

int main()
{
    printf("%u\n", sizeof(A));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它给出了输出16.如果我们考虑结构内部填充和结构填充作为一个整体,它不应该是24

我正在使用GCC 4.8.2Ubuntu 14.04 32位上编译代码.

c padding

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

通过 libnice 和 gstreamer 进行视频流传输

我想将视频从 IP 摄像机流式传输到 NAT 后面的远程 PC。为此,我使用 libnice 和 gstreamer。

一方面,我实现了以下管道。

rtspsrc <-> Nicesink

远程客户端管道

Nicesrc <-> rtph264depay <-> h264parse <-> ffdec_h264 <-> autovideosink

但是,我无法在远程客户端上获取视频流。我在远程客户端上的 Nicesrc 元素上获取视频数据包,但通过上面的管道,我无法看到视频。

我如何知道数据包正在远程客户端上的 Nicesrc 元素上:

我在 libnice 的接收回调中获取缓冲区长度打印。从那里,我还可以以 h264 格式录制视频并播放。但远程客户端上的上述管道并未发生实时流传输。

我还尝试将 capfilters 包含在 gstreamer 管道中,但没有成功。任何帮助都是appriced。谢谢

video-streaming gstreamer stun turn libnice

5
推荐指数
0
解决办法
1051
查看次数

如何知道堆栈函数消耗了多少?

最近,我在采访中遇到了这个问题:
我们如何确定特定函数消耗了堆栈上的多少存储空间?

c c++ stack

5
推荐指数
1
解决办法
2864
查看次数

不同情况下C宏的不同行为

这是代码,

#include<stdio.h>
#include<stdbool.h>

#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))                                                               

struct my_struct {
    int a, b;
//  char c;
};

int main() {
    bool cond = 1;
    BUILD_BUG_ON((sizeof(struct my_struct) % 8) != 0);
    BUILD_BUG_ON(cond);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

第一次使用BUILD_BUG_ON(条件)宏如果sizeof struct不等于8则抛出编译错误,因为条件将评估为true.但即使我提供真实条件,第二次使用宏也不会抛出编译错误.我无法理解这种行为.谁能解释一下?

c

5
推荐指数
2
解决办法
841
查看次数

将指针转换为指向数组的指针

以下是代码段.我想知道line no. 17在c中类型转换是否合法?

#include <stdio.h>

typedef int twoInts[2];

void print(twoInts *twoIntsPtr);
void intermediate (twoInts twoIntsAppearsByValue);

int main () {
    twoInts a;
    a[0] = 0;
    a[1] = 1;
    print(&a);
    intermediate(a);
    return 0;
}
void intermediate(twoInts b) {
    print((int(*)[])b); // <<< line no. 17 <<<
}

void print(twoInts *c){
    printf("%d\n%d\n", (*c)[0], (*c)[1]);
}
Run Code Online (Sandbox Code Playgroud)

此外,当我将定义更改intermediate

void intermediate(twoInts b) {
    print(&b);
}
Run Code Online (Sandbox Code Playgroud)

我在编译时遇到警告,而o/p不正确.

1.c:17:11: warning: passing argument 1 of print from incompatible pointer type
     print(&b);
           ^
1.c:5:6: note: expected int …
Run Code Online (Sandbox Code Playgroud)

c

5
推荐指数
1
解决办法
856
查看次数

打印联合变量 - 奇数行为

#include <stdio.h>

union p{
    int x;
    float y;
};

int main()
{
    union p p;
    p.x = 10; 
    printf("%f\n", p.y);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

0.000000

当我尝试编译上面的程序时,即使在main函数中也没有显示任何警告.为什么printf不打印价值10.00000

我已经阅读了一些关于stackoverflow的相关问题,它解释了printf在没有使用float说明符进行类型转换的情况下打印整数时的行为,但我认为这是一个不同的情况.我用float说明符打印浮点数.它应该打印正确的值.任何人都可以解释这里发生了什么?

c printf unions type-punning

4
推荐指数
2
解决办法
143
查看次数

在下面的伪c代码片段中应避免代码重用的方法是什么?

if(var == something) {
    A();
    B();
} else if(var == something_else) {
    A();
    B();
    C();
} else {
    assert(false);
}
Run Code Online (Sandbox Code Playgroud)

在两种if情况下,如何避免调用A()和B()的代码重用.我应该使用开关盒,

switch(var) {
case something:
case something_else:
    A();
    B();
    break;
}
if (var == something_else)
   C():
Run Code Online (Sandbox Code Playgroud)

什么是更好的解决方案?switchvs中是否存在性能损失if else

c algorithm

4
推荐指数
1
解决办法
61
查看次数