【问题标题】:Defining a struct in c在 c 中定义结构
【发布时间】:2021-06-10 17:50:23
【问题描述】:

我有这段代码

struct atmel_tc *atmel_tc_alloc(unsigned block, const char *name)
{
struct atmel_tc *tc;
/* Iterate over the list elements */
list_for_each_entry(tc, &tc_list, node) {
/* Do something with tc */
}
[...]
}

这是来自内核源文件,我对 C 有点陌生,所以我无法理解 此行struct atmel_tc *atmel_tc_alloc(unsigned block, const char *name)

到目前为止,我已经看到简单地声明为 struct atmel_tc 的结构 没有任何参数或 * ,我见过这样的用法

struct node {
int data;
struct node *next;
}*head;

其中 *head 是指向节点实例的指针。这里是否也发生了类似的事情?

您能否解释一下这一行或向我指出一些类似语法的文档

【问题讨论】:

  • 该行没有描述结构。它是函数atmel_tc_alloc的(第一行)定义,它返回一个指向结构实例的指针。

标签: c linux-kernel


【解决方案1】:
struct atmel_tc *atmel_tc_alloc(unsigned block, const char *name)

这表示atmel_tc_alloc 是一个函数,它返回一个指向struct atmel_tc 的指针,并将一个名为blockunsigned 和一个名为nameconst char * 作为参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多