Bifalgorithm post · Computer science one · Alternative Declarations

What is the alternative way to declare a structure in C?

What is the alternative way to declare a structure in C? (Computer science one · Alternative Declarations) — "In some examples and code bases you may find an a…

Ideas in this flowchart

  • Alternative declaration of a structure
  • The syntax omits typedef and places the structure name at the beginning.
  • The two declarations differ in how the structure name is placed in namespaces.
  • Example of the alternative syntax: struct Student { ... };
  • The original syntax creates an anonymous structure with Student in the global namespace.
  • The alternative declaration places Student in the structure namespace.
  • Student is therefore not available in the global scope as a type name.
  • A variable must be declared by specifying the structure: struct Student s;
Feed/

What is the alternative way to declare a structure in C?

No cover

Channel

Computer science one

1 page

"In some examples and code bases you may find an alternative way of declaring a structure that looks like the following.\n\nstruct Student {\n\n...\n\n};\n\nThis syntax omits the keyword typedef and places the structure name at the beginning. The difference is a bit technical (the original syntax creates an anonymous structure with the Student identifier placed in the global namespace, while this declaration places the Student identifier in the structure namespace), but one of the consequences of using this type of declaration is that the Student identifier is not in the global scope, so to declare a variable of the type Student you need to further specify that it is a structure using the following syntax.\n\nstruct Student s;"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.