c - 需要帮助理解这段代码

标签 c

在一个 gstreamer-plugin 中有一些代码:

static GstFlowReturn
gst_ebml_peek_id_full (GstEbmlRead * ebml, guint32 * id, guint64 * length,
    guint * prefix)
{
  GstFlowReturn ret;

  ret = gst_ebml_peek_id_length (id, length, prefix,
      (GstPeekData) gst_ebml_read_peek, (gpointer) gst_ebml_read_br (ebml),
      ebml->el, gst_ebml_read_get_pos (ebml));
  if (ret != GST_FLOW_OK)
    return ret;

  GST_LOG_OBJECT (ebml->el, "id 0x%x at offset 0x%" G_GINT64_MODIFIER "x"
      " of length %" G_GUINT64_FORMAT ", prefix %d", *id,
      gst_ebml_read_get_pos (ebml), *length, *prefix);

现在看到 gst_ebml_peek_id_length () 的第 4 个参数是

(GstPeekData) gst_ebml_read_peek

其中 gst_ebml_read_peek 是另一个函数,其定义是:

static const guint8 *
gst_ebml_read_peek (GstByteReader * br, guint peek)
{
  const guint8 *data = NULL;

  if (G_LIKELY (gst_byte_reader_peek_data (br, peek, &data)))
    return data;
  else
    return NULL;
}

现在我想问你的是:gst_ebml_read_peek在定义中有两个输入参数,那么如何不带参数调用它(在上面的代码中)?

编辑: 您可以在以下位置找到此代码 http://gstreamer.freedesktop.org/data/coverage/lcov/gst-plugins-good/gst/matroska/ebml-read.c.gcov.html

从第 194 行开始。

最佳答案

因为它是一个 function pointer .该函数此时并未实际调用,它只是传递给 gst_ebml_peek_id_length(稍后可能会使用正确的参数调用它)。

关于c - 需要帮助理解这段代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7845959/

相关文章:

C- 尝试将字符传递到 pthread_create,发生段错误

linux - 为什么程序没有执行这个C编程或unix编程中的某些语句(execvp()系统调用)?

c - 在 C 中测量没有 pthread 的开销

c - Linux 中的 DMA 如何处理 memcpy

c - C 中的安全函数是否比不安全的函数更快,反之亦然?

java - 如何在 JNI 调用中使用全局引用

c - 为什么不考虑将 strnlen() 包含在 C23 中?

c++ - 在 C/C++ 中覆盖符号

c - 为什么 C struct tm 不是 typedef?

c - 在 C 中激活数字的某些位