小编pat*_*seb的帖子

使用`NULL`指针转换说明符`p`的行为是什么?

我想知道是否:

void *ptr = NULL;
printf("%p\n", ptr);
Run Code Online (Sandbox Code Playgroud)

会不会给出(nil)输出?

它是依赖于标准库实现,还是C99标准规范?

c null printf

12
推荐指数
2
解决办法
5394
查看次数

LIST_HEAD_INIT和INIT_LIST_HEAD之间的区别

我正在尝试了解Linux内核链表API.

根据Linux内核链接列表我应该初始化列表,INIT_LIST_HEAD在这里(Linux内核程序) 建议使用它LIST_HEAD_INIT.

这是我写的一个工作代码,但我不确定我是否以正确的方式做到了.有人可以验证它没问题吗?

#include <stdio.h>
#include <stdlib.h>
#include "list.h"

typedef struct edge_attr {
        int d;
        struct list_head list;
} edge_attributes_t;

typedef struct edge {
        int id;
        edge_attributes_t *attributes;
} edge_t;

int main () {
        int i;
        struct list_head *pos;
        edge_attributes_t *elem;
        edge_t *a = (edge_t*)malloc(sizeof(edge_t));

        a->id = 12;
        a->attributes = (edge_attributes_t*) malloc(sizeof(edge_attributes_t));

        INIT_LIST_HEAD(&a->attributes->list);

        for (i=0; i<5; ++i) {
                elem = (edge_attributes_t*)malloc(sizeof(edge_attributes_t));
                elem->d = i;
                list_add(&elem->list, &a->attributes->list);
        }

        list_for_each(pos, &(a->attributes->list)) {
                elem = …
Run Code Online (Sandbox Code Playgroud)

c linked-list linux-kernel

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

Spreadsheet :: WriteExcel基于其他单元格值的条件格式

我正在尝试在Excel工作表中添加条件格式.不幸的是,Spreadsheet :: WriteExcel页面上的示例太简单了,我不知道该怎么做.

我想通过RC10单元格值更改行背景颜色.在excel中,我将添加格式化公式

=IF(RC10="xxxx";1;0)
Run Code Online (Sandbox Code Playgroud)

我试过在Spreadsheet :: WriteExcel中做类似的事情:

my $detail_rest_fmt = $excel->add_format(font => "Calibri", size => 11, valign  => "vcenter", align => "right", border => 1);
$detail_rest_fmt->set_num_format("[Green]=IF(RC10=\"xxxx\";1;0);[Red]=IF(RC10=\"yyyyyy\";1;0)"); 
Run Code Online (Sandbox Code Playgroud)

但没有任何影响.

excel perl

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

Perl无法定​​位功能,但已安装数据包

我正在使用Spreadsheet :: WriteExcel数据包来创建一些Excel文件.一切正常,但是当我尝试使用以下方法设置列宽时:

$excel->set_column("A:F",  20);
Run Code Online (Sandbox Code Playgroud)

擅长的是:

my $excel = Spreadsheet::WriteExcel->new('test.xls');
Run Code Online (Sandbox Code Playgroud)

我收到了错误:

无法通过test.pl第49行的"Spreadsheet :: WriteExcel"包找到对象方法"set_column".

我不明白,因为所有其他功能都可以.

excel perl spreadsheet

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

对我自己的库的未定义引用

我用几个创建了我的lib.a文件

gcc -c file.c -o file.o
Run Code Online (Sandbox Code Playgroud)

然后

ar sr lib/libtest.a file1.o file2.o file3.o
Run Code Online (Sandbox Code Playgroud)

确认

ar -t lib/libtest.a
file1.o
file2.o
file3.o
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译测试应用程序时

gcc lib/libtest.a test.c -o test
Run Code Online (Sandbox Code Playgroud)

我在函数中得到了未定义的引用main:来自file1.o,file2.o,file3.o的函数

c gcc static-libraries unix-ar undefined-reference

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

在自己的库中取消引用指向不完整类型的指针

我的库里有几个struct:edge,vertex,graph.我想隐藏用户的结构体(用户必须使用API​​),所以在头文件(例如edge.h)中我只是把:

typedef struct edge edge_t;
Run Code Online (Sandbox Code Playgroud)

边结构的定义在edge.c中

struct edge {...};
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我想不想隐藏自己的代码中的struct的主体.我想在edge.c中使用:

vertex_t v;
v.some_attribute = x;
Run Code Online (Sandbox Code Playgroud)

现在我得到解除指向不完整类型错误的指针,是否有可能解决这个问题?是否有任何其他选项对所有struct元素使用访问器(如用户)?

c compiler-errors

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