小编mwa*_*ing的帖子

包括在struct中更改sizeof in_addr

好的,我有一个包含struct in_addr元素的结构.这应该使struct addrlist_t至少有12个字节(8 + 4).平台是amd64.

#include <netinet/in.h> // struct in_addr
#include <stdio.h> // printf()
#include <netdb.h> // toggles size of struct addrlist_t

struct addrlist_t {
    struct addrlist_t *next;
    struct in_addr h_addr;
};

int main(int argc, char *argv[]) {
    printf("%zu + %zu = %zu\n",
        sizeof (struct addrlist_t *), sizeof (struct in_addr), 
        sizeof (struct addrlist_t)
    );
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是完全出乎意料的输出:

$cc main.c -o main -Wall -Wwrite-strings -pedantic -std=gnu99 -Wall -Werror
$./main
8 + 4 = …
Run Code Online (Sandbox Code Playgroud)

c

11
推荐指数
1
解决办法
563
查看次数

如何在没有配置的情况下使用 git 应用补丁

我写了一些使用 git 应用补丁的说明。这些说明旨在放入控制台并完成。像这样:

git am bar.patch
git am foo.patch
Run Code Online (Sandbox Code Playgroud)

但是 git 现在要求用户名/电子邮件:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@user-VirtualBox.(none)')
You need to set your committer info first
Run Code Online (Sandbox Code Playgroud)

这似乎不是必需的,因为只有补丁的作者出现在 git 日志中,而不是应用补丁的人。有没有办法忽略配置?

编辑:错别字

git configuration patch

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

使用sscanf比较字符串,但忽略空格

对于命令行应用程序,我需要将输入字符串与命令模式进行比较.需要忽略空格.

此行应匹配输入字符串,如"全部删除"和"全部删除":

int rc = sscanf( input, "drop all");
Run Code Online (Sandbox Code Playgroud)

但是什么表明这里有成功的比赛?

c scanf

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

如何对 gnuplot 中的整列求和?

我有多个像这样的 CSV 文件(只有一列):

3
4
2.3
0.1
Run Code Online (Sandbox Code Playgroud)

现在我想创建一个包含<filename>:<sum of the column>.

但目前我很难总结一个专栏:

plot 'data1.txt' using 0:(sum [col = 0:MAXCOL] (col)) with linespoint;
Run Code Online (Sandbox Code Playgroud)

gnuplot

3
推荐指数
1
解决办法
2551
查看次数

来自 recvfrom 的异常 IPv6 地址,以 a00 开头

IPv6 套接字(GNU/Linux) 上的recvfrom 为客户端/发件人地址提供不寻常的地址,格式为a00::<two_radom_bytes>:</64_network_prefix>

这些地址的名称是什么,或者通过哪些搜索词可以找到更多信息?

c ipv6

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

dbus-send 到 QDBus 程序示例

我尝试通过 dbus-send 向这个小示例程序发送消息。但没有收到:

dbus-send --session --type=method_call  / dbustester.test.slot_foo
Run Code Online (Sandbox Code Playgroud)

返回代码为 0,并且没有消息打印到控制台。

下面是源代码。

主程序

#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtDBus/QtDBus>
#include <Example.h>

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    Example *e = new Example();
    e->setupDBus();

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

示例.h

#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtDBus/QtDBus>

class Example : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "dbustester.test")
public:

    Example(QObject* parent = NULL) :
        QObject(parent)
    {
    }

    void setupDBus()
    {
        QDBusConnection session = QDBusConnection::sessionBus();

        if (!session.isConnected())
        {
            qFatal("Cannot connect to the D-Bus session …
Run Code Online (Sandbox Code Playgroud)

qt dbus

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

标签 统计

c ×3

configuration ×1

dbus ×1

git ×1

gnuplot ×1

ipv6 ×1

patch ×1

qt ×1

scanf ×1