编译器提示 "invalid type argument of ‘->’”,为什么?

标签 c

我有这个功能:

void simul(char *new)
{

    segment_table seg = malloc(sizeof(st));
    segcode newcode = malloc(sizeof(sc));
    int clen = 0;
    seg -> segname = new;
    clen = code_length(seg -> segname);
    seg -> code = read_hexcode(seg -> segname, newcode, clen);
    load_image(seg, clen-3);
    if (strstr(new, "paper_boot-strap loader.hexcode") == NULL)
            run(segment_offset(seg));
}

当我尝试编译程序时,出现以下错误:

error: ‘st’ undeclared (first use in this function)
error: ‘sc’ undeclared (first use in this function)
error: invalid type argument of ‘->’ (have ‘segment_table’)
error: invalid type argument of ‘->’ (have ‘segment_table’)
error: invalid type argument of ‘->’ (have ‘segment_table’)
error: invalid type argument of ‘->’ (have ‘segment_table’)
  • 我做错了什么?

最佳答案

头文件,例如header.h:

// First an include guard (https://en.wikipedia.org/wiki/Include_guard)
#ifndef HEADER_
#define HEADER_

// Define the structures and their type-aliases
typedef struct st { ... } st;
typedef struct sc { ... } sc;

// Declare a couple of other type-aliases
// (Note that I personally recommend against declaring pointer type-aliases)
// (I personally recommend against using type-aliases for simple types
// like the above structures too)
typedef st *segment_table;
typedef sc *segcode;

// Declare a function prototype
void simul(char *new);

#endif  // HEADER_

一个源文件

#include "header.h"

void simul(char *new)
{
    ...
}

第二个源文件

#include "header.h"

int main(void)
{
    sumul("some string");
}

关于编译器提示 "invalid type argument of ‘->’”,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33058660/

相关文章:

c++ - 以明显的方式反转位

c - C 编译器如何解析类型转换?

c - 使用 X11 编译文件时出现问题

c - union 的 _Atomic 成员是个好主意吗?

c - c中的函数指针声明

c - Qsort 字符串结构

c - 错误 : invalid type argument of unary '*' (have 'int' )

c++ - 为什么在不返回值的情况下从非 void 函数的末尾流出不会产生编译器错误?

c - 将标准输出分配给文件*

c - 一个字符是否作为带有填充的整个单词保存在内存中?