请教个结构体的问题

织田信长 2012-07-17 10:01:21
typedef struct PLNODE
{
unsigned char PlNodeID; //负载节点的ID
unsigned char PlNodeListenPort; //负载节点的监听端口
unsigned char PlNodeSendPort; //负载节点的发送端口
unsigned char PlNodeStatus; //节点状态字
int PlNodeUserNum; //节点当前使用的人数
int MaxUserInPlNode; //该节点的最大用户数
int UserID[MAX_USER]; //用户列表
};


typedef struct PLNODE_LIST
{
PLNODE* PtrPlNode[MAX_NODE_EX]; //指向负载节点数据结构的指针
int MaxSuportNodeNum; //最大支持的节点数
int AliveNodeNum; //正在使用的节点数
};


c:\code\hoho2\sysctrlnode\structex.h(106) : error C2061: syntax error : identifier 'PLNODE'
c:\code\hoho2\sysctrlnode\structex.h(109) : error C2059: syntax error : '}'
c:\code\hoho2\sysctrlnode\structex.h(120) : error C2061: syntax error : identifier 'PLNODE_LIST'
c:\code\hoho2\sysctrlnode\structex.h(122) : error C2059: syntax error : '}'
c:\code\hoho2\sysctrlnode\recovery.h(45) : error C2143: syntax error : missing ')' before '*'
c:\code\hoho2\sysctrlnode\recovery.h(45) : error C2081: 'SYS_CTRL_NODE_MANAGER' : name in formal parameter list illegal
c:\code\hoho2\sysctrlnode\recovery.h(45) : error C2143: syntax error : missing '{' before '*'
c:\code\hoho2\sysctrlnode\recovery.h(45) : error C2059: syntax error : 'type'
c:\code\hoho2\sysctrlnode\recovery.h(45) : error C2059: syntax error : ')'
c:\code\hoho2\sysctrlnode\recovery.c(11) : error C2143: syntax error : missing ')' before '*'
c:\code\hoho2\sysctrlnode\recovery.c(11) : error C2081: 'SYS_CTRL_NODE_MANAGER' : name in formal parameter list illegal
c:\code\hoho2\sysctrlnode\recovery.c(11) : error C2143: syntax error : missing '{' before '*'
c:\code\hoho2\sysctrlnode\recovery.c(11) : error C2059: syntax error : 'type'
c:\code\hoho2\sysctrlnode\recovery.c(11) : error C2059: syntax error : ')'

很困惑是结构体这样定义有问题吗?
...全文
360 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
珠琪 2013-01-17
  • 打赏
  • 举报
回复
究竟谁说的对呀
织田信长 2012-07-23
  • 打赏
  • 举报
回复
谢谢大家了,没想到这么多人回复
OSTnm 2012-07-22
  • 打赏
  • 举报
回复
无问题 这个表示PLNODE代表这个结构体定义类型
MFCANDPAI 2012-07-22
  • 打赏
  • 举报
回复
这其实是格式的问题,楼主试试各种格式就行了
Caworb 2012-07-22
  • 打赏
  • 举报
回复
typedef的问题!在结构体完结的分号前要加上该结构体的别名!
在C中使用结构体需要写成:struct Sname
所以为了省略个struct而用typedef…(其实还有其它原因)
而CPP中就已经可以不用struct而直接用结构体名了!所以也可以不加typedef了…
楼主查下typedef的用法就好了…
litao_yuanyuan 2012-07-21
  • 打赏
  • 举报
回复
typedef说简单就是取别名的意思,你那个没有别名,所以不对
PIE 2012-07-21
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
typedef struct PLNODE
{
unsigned char PlNodeID; //负载节点的ID
unsigned char PlNodeListenPort; //负载节点的监听端口
unsigned char PlNodeSendPort; //负载节点的发送端口
unsigned char PlNodeStatus; //节点状态字
int Pl……
[/Quote]顶一个
ProgrammingRing 2012-07-18
  • 打赏
  • 举报
回复
typedef定义新的类型,你第二个用了typedef但没给新的名字啊,第一个要用的话得价格struct PLNODE * XXXX;
jiandingzhe 2012-07-18
  • 打赏
  • 举报
回复
应当是:

typedef struct { } TypeName;
赵4老师 2012-07-18
  • 打赏
  • 举报
回复
Typedef Declarations
A typedef declaration is a declaration with typedef as the storage class. The declarator becomes a new type. You can use typedef declarations to construct shorter or more meaningful names for types already defined by C or for types that you have declared. Typedef names allow you to encapsulate implementation details that may change.

A typedef declaration is interpreted in the same way as a variable or function declaration, but the identifier, instead of assuming the type specified by the declaration, becomes a synonym for the type.

Syntax

declaration :

declaration-specifiers init-declarator-list opt ;

declaration-specifiers :

storage-class-specifier declaration-specifiers opt
type-specifier declaration-specifiers opt
type-qualifier declaration-specifiers opt

storage-class-specifier :

typedef

type-specifier :

void
char
short
int
long
float
double
signed
unsigned
struct-or-union-specifier
enum-specifier
typedef-name

typedef-name :

identifier

Note that a typedef declaration does not create types. It creates synonyms for existing types, or names for types that could be specified in other ways. When a typedef name is used as a type specifier, it can be combined with certain type specifiers, but not others. Acceptable modifiers include const and volatile.

Typedef names share the name space with ordinary identifiers (see Name Spaces in Chapter 2 for more information). Therefore, a program can have a typedef name and a local-scope identifier by the same name. For example:

typedef char FlagType;

int main()
{
}

int myproc( int )
{
int FlagType;
}

When declaring a local-scope identifier by the same name as a typedef, or when declaring a member of a structure or union in the same scope or in an inner scope, the type specifier must be specified. This example illustrates this constraint:

typedef char FlagType;
const FlagType x;

To reuse the FlagType name for an identifier, a structure member, or a union member, the type must be provided:

const int FlagType; /* Type specifier required */

It is not sufficient to say

const FlagType; /* Incomplete specification */

because the FlagType is taken to be part of the type, not an identifier that is being redeclared. This declaration is taken to be an illegal declaration like

int; /* Illegal declaration */

You can declare any type with typedef, including pointer, function, and array types. You can declare a typedef name for a pointer to a structure or union type before you define the structure or union type, as long as the definition has the same visibility as the declaration.

Typedef names can be used to improve code readability. All three of the following declarations of signal specify exactly the same type, the first without making use of any typedef names.

typedef void fv( int ), (*pfv)( int ); /* typedef declarations */

void ( *signal( int, void (*) (int)) ) ( int );
fv *signal( int, fv * ); /* Uses typedef type */
pfv signal( int, pfv ); /* Uses typedef type */

Examples

The following examples illustrate typedef declarations:

typedef int WHOLE; /* Declares WHOLE to be a synonym for int */

Note that WHOLE could now be used in a variable declaration such as WHOLE i; or const WHOLE i;. However, the declaration long WHOLE i; would be illegal.

typedef struct club
{
char name[30];
int size, year;
} GROUP;

This statement declares GROUP as a structure type with three members. Since a structure tag, club, is also specified, either the typedef name (GROUP) or the structure tag can be used in declarations. You must use the struct keyword with the tag, and you cannot use the struct keyword with the typedef name.

typedef GROUP *PG; /* Uses the previous typedef name
to declare a pointer */

The type PG is declared as a pointer to the GROUP type, which in turn is defined as a structure type.

typedef void DRAWF( int, int );

This example provides the type DRAWF for a function returning no value and taking two int arguments. This means, for example, that the declaration

DRAWF box;

is equivalent to the declaration

void box( int, int );

浮生专栏 2012-07-17
  • 打赏
  • 举报
回复
既然写了typedef,在结构体最后怎么没写别名,C语言对着可能有要求,我的VS坏了,不能测试,楼主自己测一下吧。
织田信长 2012-07-17
  • 打赏
  • 举报
回复
typedef struct PLNODE
{
unsigned char PlNodeID; //负载节点的ID
unsigned char PlNodeListenPort; //负载节点的监听端口
unsigned char PlNodeSendPort; //负载节点的发送端口
unsigned char PlNodeStatus; //节点状态字
int PlNodeUserNum; //节点当前使用的人数
int MaxUserInPlNode; //该节点的最大用户数
int UserID[MAX_USER]; //用户列表
}PLNODE;

这么写就好了…… 不知道原因……
W170532934 2012-07-17
  • 打赏
  • 举报
回复
第二个结构体的typedef也是要去掉的
W170532934 2012-07-17
  • 打赏
  • 举报
回复
定义的第一个结构体没有起别名,为什么要使用typedef??把这个typedef去掉吧!
C语言课程设计是一个旨在帮助学生深入理解和应用C语言编程的实践项目。以下是一些关于C语言课程设计的基本步骤和建议: 明确目标和需求:首先,你需要与授课教师或课程设计的相关人员沟通,明确课程设计的需求。这包括了解课程设计的主题、目标以及需要解决的问题。这将有助于你确定设计的范围和方向。 选择项目主题:选择一个与C语言相关的项目主题。例如,你可以设计一个学生成绩管理系统、一个简单的文本编辑器或一个游戏等。确保所选主题既具有挑战性又能够展示你的C语言编程技能。 进行问题分析:一旦确定了项目主题,你需要对问题进行深入分析。这包括确定问题的输入和输出、理解问题的要求和限制条件,以及将复杂问题分解为更小的子问题。这将有助于你更好地理解和解决问题。 设计算法和数据结构:针对项目需求,设计合适的算法和数据结构。这包括确定如何存储和处理数据、如何设计函数和模块等。 编写代码:使用C语言编写代码,实现项目功能。注意遵守C语言的语法规则,确保代码的可读性和可维护性。 测试和调试:在编写完代码后,进行测试和调试。确保代码能够正确运行并满足项目需求。使用调试工具和技术来查找和修复代码中的错误。 文档编写:编写项目文档,包括项目说明、功能介绍、代码注释等。这将有助于其他人理解你的项目并复用你的代码。 提交和展示:最后,将你的课程设计项目提交给教师或相关人员,并在课堂上进行展示。展示时可以介绍项目的功能、实现过程以及遇到的挑战和解决方案等。 在进行C语言课程设计时,还需要注意以下几点: 遵守编程规范,包括变量命名、代码缩进、注释等。 充分利用C语言的特点和优势,如指针、结构体、文件操作等。 注重实践和应用,通过解决实际问题来加深对C语言的理解和应用能力。 在遇到困难时,及时向教师或同学请教,并查阅相关资料和文档。 通过以上步骤和建议,你可以完成一个高质量的C语言课程设计项目,并提升自己的编程能力和实践经验。
C语言课程设计是一个旨在帮助学生深入理解和应用C语言编程的实践项目。以下是一些关于C语言课程设计的基本步骤和建议: 明确目标和需求:首先,你需要与授课教师或课程设计的相关人员沟通,明确课程设计的需求。这包括了解课程设计的主题、目标以及需要解决的问题。这将有助于你确定设计的范围和方向。 选择项目主题:选择一个与C语言相关的项目主题。例如,你可以设计一个学生成绩管理系统、一个简单的文本编辑器或一个游戏等。确保所选主题既具有挑战性又能够展示你的C语言编程技能。 进行问题分析:一旦确定了项目主题,你需要对问题进行深入分析。这包括确定问题的输入和输出、理解问题的要求和限制条件,以及将复杂问题分解为更小的子问题。这将有助于你更好地理解和解决问题。 设计算法和数据结构:针对项目需求,设计合适的算法和数据结构。这包括确定如何存储和处理数据、如何设计函数和模块等。 编写代码:使用C语言编写代码,实现项目功能。注意遵守C语言的语法规则,确保代码的可读性和可维护性。 测试和调试:在编写完代码后,进行测试和调试。确保代码能够正确运行并满足项目需求。使用调试工具和技术来查找和修复代码中的错误。 文档编写:编写项目文档,包括项目说明、功能介绍、代码注释等。这将有助于其他人理解你的项目并复用你的代码。 提交和展示:最后,将你的课程设计项目提交给教师或相关人员,并在课堂上进行展示。展示时可以介绍项目的功能、实现过程以及遇到的挑战和解决方案等。 在进行C语言课程设计时,还需要注意以下几点: 遵守编程规范,包括变量命名、代码缩进、注释等。 充分利用C语言的特点和优势,如指针、结构体、文件操作等。 注重实践和应用,通过解决实际问题来加深对C语言的理解和应用能力。 在遇到困难时,及时向教师或同学请教,并查阅相关资料和文档。 通过以上步骤和建议,你可以完成一个高质量的C语言课程设计项目,并提升自己的编程能力和实践经验。
C语言课程设计是一个旨在帮助学生深入理解和应用C语言编程的实践项目。以下是一些关于C语言课程设计的基本步骤和建议: 明确目标和需求:首先,你需要与授课教师或课程设计的相关人员沟通,明确课程设计的需求。这包括了解课程设计的主题、目标以及需要解决的问题。这将有助于你确定设计的范围和方向。 选择项目主题:选择一个与C语言相关的项目主题。例如,你可以设计一个学生成绩管理系统、一个简单的文本编辑器或一个游戏等。确保所选主题既具有挑战性又能够展示你的C语言编程技能。 进行问题分析:一旦确定了项目主题,你需要对问题进行深入分析。这包括确定问题的输入和输出、理解问题的要求和限制条件,以及将复杂问题分解为更小的子问题。这将有助于你更好地理解和解决问题。 设计算法和数据结构:针对项目需求,设计合适的算法和数据结构。这包括确定如何存储和处理数据、如何设计函数和模块等。 编写代码:使用C语言编写代码,实现项目功能。注意遵守C语言的语法规则,确保代码的可读性和可维护性。 测试和调试:在编写完代码后,进行测试和调试。确保代码能够正确运行并满足项目需求。使用调试工具和技术来查找和修复代码中的错误。 文档编写:编写项目文档,包括项目说明、功能介绍、代码注释等。这将有助于其他人理解你的项目并复用你的代码。 提交和展示:最后,将你的课程设计项目提交给教师或相关人员,并在课堂上进行展示。展示时可以介绍项目的功能、实现过程以及遇到的挑战和解决方案等。 在进行C语言课程设计时,还需要注意以下几点: 遵守编程规范,包括变量命名、代码缩进、注释等。 充分利用C语言的特点和优势,如指针、结构体、文件操作等。 注重实践和应用,通过解决实际问题来加深对C语言的理解和应用能力。 在遇到困难时,及时向教师或同学请教,并查阅相关资料和文档。 通过以上步骤和建议,你可以完成一个高质量的C语言课程设计项目,并提升自己的编程能力和实践经验。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧