Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C Structs and Typedef

Name: Anonymous 2013-10-24 14:48

Help me understand structs and typedef.

What is the difference between:
struct tag_name{ type member; }
typedef struct tag_name{ type member; } struct_alias;

Why is the tag_name optional in number 2 if there is no self-referential pointer?

When creating an instance of a struct, when do you have to use:
tag_name instance;
and when:
struct tag_name instance;
?

Is using:
typedef struct tag{} alias
making it possible to say:
alias instance;
instead of:
struct tag instance;
?

Also when is the tag needed there?
How do you create an instance of:
typedef struct {} alias

Name: Anonymous 2013-10-24 15:09

*YOU HAVE BEEN VISITED BY LE TOP LEL OF COMEDY GOLD** POST THIS IN 3 threads or lose your sides!
░░░░░░░▄▀▀▀░▄▄▄▄░░░▀▀▀▀▀▀▀▀▄▄░▀
░░░░░░░█░░░░░░░░▀▀▀▀▀▄▄▄▄▄▄▄▄▀░░█
░░░░░▄▀░░░░░░░░░░▄░░░░░░░░▄▄░░░░░▀▄
░░░▄▀░░░░░▄▀▀▀█▄░▀░░░░▄▀▀▀██▀▀▄░░░░░▀
░░▄▀░░▄▄░░▀▀▀▀████▀░░░▀▄▄▀▀▀▀▄█░░░░░░█
░▄▀░▄▀█░░▄▄░░░░░░░█░░░░░▄▄▄░░░▀▀░░░░░░█
▄▀░░█░█░▀░░▀▀▄░░░░░█░░░░░░░▀▀▀▀▀▄░░░░░█
▀▄░░▀░█░░░▄░░░░░░▄▀░░░░▀▄░░░▄▄░░▀▄░█░▄▀
░░▀▄░░░░█▀▄░░░░░▀█░░░░▀▀░█▄▀▄░█░░░█░█
░░░░█░░█░▀▄▀▄▄░░░░▀▀▀░░░▄█▀░▄▀█░░░░▄
░░░░░█░░█░▀▀▄░▀▄▄▄▄▄▄▄▀█░▄█▀▄▀░░░░░
░░░░░█░░▀▄▄░░▀█░░░█░░▄▄▀▀▄▄█▀░░░░▀
░░░░▄▀░░░▀▄▀▀▄░▀▀▀▀▀▀▄▄▀▀▀▄▀░░░░▀
░░░▄▀░░░░░░▀▄░█▄▄▄▄▀▀░▀▄▀▀░░░▄▀▀
░░▄▀░░░░░░░░░▀▄▄▄▄█▄▄▀▀░░░░▄
░░█░░░░░░▀▄▄░░░▄▄▄▄▄▄▀░░░▄▀
░░█░░░░░░░░░▀▀▀▄▄▄▄▄▄▄▀▀
░░░█░░░░░░▀▀▀▀▀░░░░▄
░░░▀▀▄▄▄▄▄▄▄▄▄▀▀▀

Name: Anonymous 2013-10-24 15:10

Use C++ and classes instead.

Name: Anonymous 2013-10-24 15:14

Using C++ won't help me understand C any better.

Name: Anonymous 2013-10-24 15:55

>>4
You haven't tried

Name: Anonymous 2013-10-24 16:22

sir lelington

Name: Anonymous 2013-10-24 17:14

>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2>>2
>─────▄████▀█▄
  >───▄█████████████████▄
  >─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
  >▄███████▄.▲.▲▲▲▲▲▲▲▲
  >███████████████████▀▀
  YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!

Name: Anonymous 2013-10-24 17:27

>─────▄████▀█▄
  >───▄█████████████████▄
  >─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
  >▄███████▄.▲.▲▲▲▲▲▲▲▲
  >███████████████████▀▀
  YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!

Name: Anonymous 2013-10-24 21:53

Just fucking read K&R2 and stop asking stupid quesitons.

Name: Anonymous 2013-10-24 22:50

Most of your questions are answered by these few points:

1. Unsure? Try compiling it, changing it, compiling it again.
2. "typedef" makes an alias of another type. e.g. "typedef int** ppint;" would make a "ppint" type exactly equivalent to "int**". It follows a similar syntax to variable declarations except it declares a type instead of a variable.
3. You can give typedef structs an empty tag for the same reason you can give struct variables an empty tag, e.g.
struct {
  int x, y;
} shit;

The reason is that you can refer to the typedef or variable by its actual name.
4. In the self-referential pointer case you should be asking why it's not possible to use the typedef - and the answer is because the typedef is evaluated only after the struct has been parsed.

Name: Anonymous 2013-10-24 22:59

Dubs.

Name: Anonymous 2013-10-24 23:00

>>11
Well fuck me! My system clock is a few seconds ahead it seems. I'm sorry guys, I really dropped the ball on this one.

Name: Anonymous 2013-10-24 23:43

>>9
>le pedophile sage

Name: Anonymous 2013-10-26 19:28

>>11
check ''em

Name: Anonymous 2013-11-02 7:19

install gentoo

Name: Anonymous 2013-11-02 8:01

>>1
In addition to what >>10-san said, for historical reasons struct tags live in a different namespace in C -- if you have a struct type named "s", you have to always refer to it as "struct s". Which, together with a separate namespace for values, allows http://ideone.com/JQJ0nd

Name: Anonymous 2013-11-02 10:41

>le pedophile san

Name: Anonymous 2013-11-02 15:44

So how many different identificator/tag namespaces does C have in all, five?

- variable tags
- type tags
- struct tags
- struct field tags
- label tags (for the goto shit)

Did I miss anything?

Name: Anonymous 2013-11-02 17:10

>>18
It turned out that I lied about the separate namespace for values, it after a bork bork; declaration bork begins to refer to the variable.

Anyway,

6.2.3 Name spaces of identifiers

If more than one declaration of a particular identifier is visible at any point in a translation unit, the syntactic context disambiguates uses that refer to different entities. Thus, there are separate name spaces for various categories of identifiers, as follows:
— label names (disambiguated by the syntax of the label declaration and use);
— the tags of structures, unions, and enumerations (disambiguated by following any) of the keywords struct, union, or enum);
— the members of structures or unions; each structure or union has a separate name space for its members (disambiguated by the type of the expression used to access the member via the . or -> operator);
— all other identifiers, called ordinary identifiers (declared in ordinary declarators or as
enumeration constants).

Name: Anonymous 2013-11-02 20:48

*YOU HAVE BEEN VISITED BY LE TOP LEL OF COMEDY GOLD** POST THIS IN 3 threads or lose your sides!
░░░░░░░▄▀▀▀░▄▄▄▄░░░▀▀▀▀▀▀▀▀▄▄░▀
░░░░░░░█░░░░░░░░▀▀▀▀▀▄▄▄▄▄▄▄▄▀░░█
░░░░░▄▀░░░░░░░░░░▄░░░░░░░░▄▄░░░░░▀▄
░░░▄▀░░░░░▄▀▀▀█▄░▀░░░░▄▀▀▀██▀▀▄░░░░░▀
░░▄▀░░▄▄░░▀▀▀▀████▀░░░▀▄▄▀▀▀▀▄█░░░░░░█
░▄▀░▄▀█░░▄▄░░░░░░░█░░░░░▄▄▄░░░▀▀░░░░░░█
▄▀░░█░█░▀░░▀▀▄░░░░░█░░░░░░░▀▀▀▀▀▄░░░░░█
▀▄░░▀░█░░░▄░░░░░░▄▀░░░░▀▄░░░▄▄░░▀▄░█░▄▀
░░▀▄░░░░█▀▄░░░░░▀█░░░░▀▀░█▄▀▄░█░░░█░█
░░░░█░░█░▀▄▀▄▄░░░░▀▀▀░░░▄█▀░▄▀█░░░░▄
░░░░░█░░█░▀▀▄░▀▄▄▄▄▄▄▄▀█░▄█▀▄▀░░░░░
░░░░░█░░▀▄▄░░▀█░░░█░░▄▄▀▀▄▄█▀░░░░▀
░░░░▄▀░░░▀▄▀▀▄░▀▀▀▀▀▀▄▄▀▀▀▄▀░░░░▀
░░░▄▀░░░░░░▀▄░█▄▄▄▄▀▀░▀▄▀▀░░░▄▀▀
░░▄▀░░░░░░░░░▀▄▄▄▄█▄▄▀▀░░░░▄
░░█░░░░░░▀▄▄░░░▄▄▄▄▄▄▀░░░▄▀
░░█░░░░░░░░░▀▀▀▄▄▄▄▄▄▄▀▀
░░░█░░░░░░▀▀▀▀▀░░░░▄
░░░▀▀▄▄▄▄▄▄▄▄▄▀▀▀

Name: Anonymous 2013-11-03 12:36

>>18
identificator
Russiafag detected.

Name: Anonymous 2013-11-04 3:05

dubs

Don't change these.
Name: Email:
Entire Thread Thread List