’”,为什么?-6ren"> ’”,为什么?-我有这个功能: void simul(char *new) { segment_table seg = malloc(sizeof(st)); segcode newcode = ma-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:44:52 25 4
gpt4 key购买 nike

我有这个功能:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com