[英]“excess elements in scalar initializer” when using igraph C library to generate a network with power law degree distribution
I'm using igraph C library and I want to generate a undirected, without loop, and a single edge network with power law degree distribution. 我正在使用igraph C库,并且想生成一个无向,无循环和具有幂律度分布的单边缘网络。 The parameters I have are:
我有的参数是:
I want to use the igraph_static_power_law_game
graph generator and I wrote the following code. 我想使用
igraph_static_power_law_game
图生成器,并编写了以下代码。
#include <igraph.h>
int main() {
igraph_t g;
int igraph_static_power_law_game(&g, 25000, 25000, 2.16104, -1, 0, 0, 1);
igraph_destroy(&g);
return 0;
}
I use the the following command to compile the code. 我使用以下命令来编译代码。
gcc testpw.cpp -I/usr/local/Cellar/igraph/0.7.1/include/igraph -L/usr/local/Cellar/igraph/0.7.1/lib -ligraph -o testpw
And the following error appeared. 并且出现以下错误。
error: excess elements in scalar initializer
int igraph_static_power_law_game(&g, 25000, 25000, 2.16104, -1, 0, 0, 1);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Since I can't find an example of using igraph C library to generate power-law degree network online, I don't know what's the way to make it. 由于我找不到使用igraph C库在线生成幂律度网络的示例,因此我不知道该怎么做。 Am I doing something wrong here?
我在这里做错什么了吗?
If you're compiling C code, you don't need the int
before igraph_static_power_law_game()
, because that makes the line look like a faulty declaration of the function instead of an invocation of the function. 如果要编译C代码,则在
igraph_static_power_law_game()
之前不需要int
,因为这会使该行看起来像是函数的错误声明,而不是函数的调用。
Or, if you're compiling C++ code, the compiler is interpreting the contents of the parentheses as an initializer for the variable igraph_static_power_law_game
and complaining that a single int
variable does not need multiple initializers. 或者,如果您正在编译C ++代码,则编译器会将括号的内容解释为变量
igraph_static_power_law_game
的初始化程序,并抱怨单个int
变量不需要多个初始化程序。
Either way, writing: 无论哪种方式,写:
igraph_static_power_law_game(&g, 25000, 25000, 2.16104, -1, 0, 0, 1);
fixes the immediate compilation error. 修复了立即编译错误。 You should probably be using something like:
您可能应该使用类似:
if (igraph_static_power_law_game(&g, 25000, 25000, 2.16104, -1, 0, 0, 1) != 0)
…report error…
so that if the function fails, you know about it. 这样,如果函数失败,您就知道了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.