开发者

How does this function work?

I've been dissecting gsl libraries abd came across the header file gsl_block_double.h and multiple source files with its functions definitions. One of the many is the block_source.c. i dont know C so I am not sure how those functions work and how I should go about implementing them in C++. Anyway, here are the header and source file with definitions to two of its functions:

#ifndef __GSL_BLOCK_DOUBLE_H__
#define __GSL_BLOCK_DOUBLE_H__

#include <stdlib.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_types.h>

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif

__BEGIN_DECLS

struct gsl_block_struct
{
  size_t size;
  double *data;
};

typedef struct gsl_block_struct gsl_block;

GSL_EXPORT gsl_block *gsl_block_alloc (const size_t n);
GSL_EXPORT gsl_block *gsl_block_calloc (const size_t n);
GSL_EXPORT void gsl_block_free (gsl_block * b);

GSL_EXPORT int gsl_block_fread (FILE * stream, gsl_block * b);
GSL_EXPORT int gsl_block_fwrite (FILE * stream, const gsl_block * b);
GSL_EXPORT int gsl_block_fscanf (FILE * stream, gsl_block * b);
GSL_EXPORT int gsl_block_fprintf (FILE * stream, const gsl_block * b, const char *format);

GSL_EXPORT int gsl_block_raw_fread (FILE 开发者_如何学Go* stream, double * b, const size_t n, const size_t stride);
GSL_EXPORT int gsl_block_raw_fwrite (FILE * stream, const double * b, const size_t n, const size_t stride);
GSL_EXPORT int gsl_block_raw_fscanf (FILE * stream, double * b, const size_t n, const size_t stride);
GSL_EXPORT int gsl_block_raw_fprintf (FILE * stream, const double * b, const size_t n, const size_t stride, const char *format);

GSL_EXPORT size_t gsl_block_size (const gsl_block * b);
GSL_EXPORT double * gsl_block_data (const gsl_block * b);

__END_DECLS

#endif /* __GSL_BLOCK_DOUBLE_H__ */

// block_source.c

size_t
FUNCTION(gsl_block,size) (const TYPE(gsl_block) * b)
{
  return b->size ;
}

ATOMIC *
FUNCTION(gsl_block,data) (const TYPE(gsl_block) * b)
{
  return b->data ;
}

Any help would be greatly appreciated! Thank you.

EDIT: I feel like i need to specify that the functions defined are:

size_t gsl_block_size (const gsl_block * b);
double * gsl_block_data (const gsl_block * b);


What exactly you do not understand is not clear to me from the question? I don't know what FUNCTION macro is, but what you see here are probably two OOP get functions.

You can think of it as object of type gsl_block (in c++, probably name differently), which has two get functions for the internal raw data (b->data), and one for its size (b->size).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜