简体   繁体   English

了解GNU科学图书馆文档

[英]Understanding GNU Scientific Library documentation

I'm trying to use the GNU Scientific Library and am having trouble understanding its documentation. 我正在尝试使用GNU科学库,但在理解其文档时遇到了麻烦。 Here's the sample program from the page on gsl_rng_env_setup : 这是gsl_rng_env_setup页面上的示例程序:

#include <stdio.h>
#include <gsl/gsl_rng.h>

gsl_rng * r;  /* global generator */

int
main (void)
{
  const gsl_rng_type * T;

  gsl_rng_env_setup();

  T = gsl_rng_default;
  r = gsl_rng_alloc (T);

  printf ("generator type: %s\n", gsl_rng_name (r));
  printf ("seed = %lu\n", gsl_rng_default_seed);
  printf ("first value = %lu\n", gsl_rng_get (r));

  gsl_rng_free (r);
  return 0;
}

My problems start with the third line, gsl_rng * r. 我的问题从第三行gsl_rng * r开始。 This is clearly not multiplication (neither variable defined yet), so it must be pointer notation. 显然这不是乘法(尚未定义任何变量),因此它必须是指针符号。 However from the C++ tutorial on pointers , I would expect something like gsl_rng = *r, which would take the value of r and store that as gsl_rng. 但是,从C ++指针指南中 ,我希望看到gsl_rng = * r之类的东西,它将采用r的值并将其存储为gsl_rng。 My guess is that gsl_rng isn't a variable, but some GNU Scientific library command; 我的猜测是gsl_rng不是变量,而是一些GNU Scientific库命令; however I don't understand the documentation page for it also: this command is clearly not of the form gsl_rng * gsl_rng_alloc (const gsl_rng_type * T) - even if r = gsl_rng_alloc, this command doesn't have brackets. 但我不明白的文档页面的同时也:这个命令显然不是形式gsl_rng * gsl_rng_alloc(常量gsl_rng_type * T)的-即使R = gsl_rng_alloc,该命令没有括号。

It doesn't help that a bit further down we have the line const gsl_rng_type * T which is of the same form but also clearly does something different. 再往下走,我们有一行const gsl_rng_type * T,它的形式相同,但显然也有不同之处,这无济于事。 This line seems to be defining gsl_rng_type as a constant, and assigning it the value of *T - but this is missing an assignment operator. 该行似乎将gsl_rng_type定义为常量,并为其分配* T值-但这缺少赋值运算符。 Yet T must be a variable, since a few lines later it's assigned the value of gsl_rng_default ... 但是T必须是一个变量,因为几行之后它被赋值为gsl_rng_default ...

My problems seem to be extremely basic which is troubling. 我的问题似乎非常基本,令人不安。 Can anyone point me in the right direction? 谁能指出我正确的方向?

gsl_rng is a type. gsl_rng是一种类型。 The statement gsl_rng * r; 语句gsl_rng * r; declares a global variable named r with type pointer to gsl_rng . 声明一个名为r的全局变量,其类型指针指向gsl_rng Later, there is this line r = gsl_rng_alloc (T); 稍后,这行是r = gsl_rng_alloc (T); , which assigns some value to that declared variable. ,它为声明的变量分配一些值。

This is basic C++, so maybe you should start with some good book , if you want to understand such code. 这是基本的C ++,因此,如果您想了解这样的代码,也许应该从一本好书开始。

The trick is to remember that there are different kinds of random number generators. 诀窍是要记住,存在不同种类的随机数生成器。 Each one is its' own class. 每个人都是自己的班级。 The gsl_rng_alloc method will create a random number generator object for you but wants to know what class to use. gsl_rng_alloc方法将为您创建一个随机数生成器对象 ,但想知道要使用哪个类。 You tell it what class to use by passing the class. 您可以通过传递类来告诉它要使用的类。 Then the method uses that class to instantiate an object for you. 然后,该方法使用该类为您实例化一个对象。 It returns to you a pointer to the object that it created for you. 它向您返回指向它为您创建的对象的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM