我有这个功能:
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/