Typedef struct and struct define struct

Source: Internet
Author: User

Today, when defining struct, we found that the typedef struct and struct have some differences:

Structure is also a type of data. You can use Structure Variables. Therefore, like other types of variables, you must first define them when using structure variables.
The general format for defining structure variables is:
Struct structure name
{

Type variable name;

Type variable name;

...

}Structure Variable;

 The structure name is the structure identifier, not the variable name.
Another common format is:
Typedef struct structure name
{

Type variable name;

Type variable name;

...

}Structure alias;
Note: In C, struct cannot contain functions. In C ++, struct is expanded to include functions.

GCC errors in programming:Expected specifier-qualifier-list before something. I checked the cause of the error on the Internet and explained it as follows:

When GCC is used, errors such as expected specifier-qualifier-list before… are often encountered. Specifiers refers to void, Char, struct Foo and other words; qualifiers refers to keywords such as const and volatile.This error occurs when a word is used before it is undefined,You can use typedef for definition and later. The error statement is as follows:

Typedef struct {int name [20]; int ID; Stu * Next; // error} Stu;
Solution
Typedef struct {int name [20]; int ID; struct Stu * Next; // compiled} Stu;
Defining struct with struct also has the same problem, and the solution is the same.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.