惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - SPARON

[转] 在 Windows Server 2008 R2 下用 Visual Studio 2010 编译 Chrome 与 WebKit Chromium Port [转]JVM调优总结 6 个基于 HTML5 实现的多媒体播放器 35个五彩缤纷的网页设计作品欣赏 关于setInterval调用对象方法的问题 【收藏】27个jQuery表单插件分享 【收藏】开发人员看过来:11 个免费的开源 IDE Web开发人员应当知道的15个开源项目 终于还是走到了这步! 【转】27 款经典的CSS 框架 如果收购SUN的是Microsoft... CreateFileMapping和MapViewOfFile函数 XP安装 安全补丁KB905414 后本地连接丢失的解决方法 C、CPP const 详解 C语言运算符优先级 详细列表 C语言学习之#define用法 [转]JDK里的设计模式 记CPU的一次复频 C语言字符串转数值
typedef struct和struct定义结构体的区别
SPARON · 2010-12-06 · via 博客园 - SPARON

[知识点] 

结构也是一种数据类型, 可以使用结构变量, 因此, 像其它类型的变量一样, 在使用结构变量时要先对其定义。

定义结构变量的一般格式为: 

struct 结构名
{
      类型 变量名;
      类型 变量名;
      ...
} 结构变量;

结构名是结构的标识符不是变量名。

另一种常用格式为:

typedef struct 结构名
{
      类型 变量名;
      类型 变量名;
      ...
} 结构别名;
   

另外注意: 在C中,struct不能包含函数。在C++中,对struct进行了扩展,可以包含函数。

下面分三块来讲述:

1 首先:

在C中定义一个结构体类型要用typedef:

typedef struct Student
{
    
int a;
}Stu;

于是在声明变量的时候就可:Stu stu1;

如果没有typedef就必须用struct Student stu1;来声明

这里的Stu实际上就是struct Student的别名。

另外这里也可以不写Student(于是也不能struct Student stu1;了)

typedef struct
{
    
int a;
}Stu;

但在c++里很简单,直接

struct Student
{
    
int a;
};

于是就定义了结构体类型Student,声明变量时直接Student stu2;

===========================================

2其次:

在c++中如果用typedef的话,又会造成区别:

struct   Student   
{   
    
int   a;   
}stu1;
//stu1是一个变量 
  
typedef   
struct   Student2   
{   
    
int   a;   
}stu2;
//stu2是一个结构体类型   

使用时可以直接访问stu1.a

但是stu2则必须先   stu2 s2;

然后               s2.a=10;

===========================================

3 掌握上面两条就可以了,不过最后我们探讨个没多大关系的问题

如果在c程序中我们写:

typedef struct  
{
    
int num;
    
int age;
}aaa,bbb,ccc;

这算什么呢?

我个人观察编译器(VC6)的理解,这相当于

typedef struct  
{
    
int num;
    
int age;
}aaa;
typedef aaa bbb;
typedef aaa ccc;

也就是说aaa,bbb,ccc三者都是结构体类型。声明变量时用任何一个都可以,在c++中也是如此。但是要注意的是这个在c++中如果写掉了typedef关键字,那么aaa,bbb,ccc将是截然不同的三个对象。