| Physics and Astronomy |
|
Back to top
On this page
Contents Appendix: Some minor points about structures and typedef.Definition and declaration can be combined.It's possible, although extremely rare, to combine the definition and declaration together. Here we define a structure type and declare an actual structure, mystruct:
int main() {
// More stuff here..
(Note no word "typedef").
Structures can be initialised at declarationSo to continue the previous example we may declare another structure and initialise it: Any declaration can be made into a typedefSharp-eyed readers may have noticed that our example typical structure typedef in the main notes:
#define MAXLEN 64
typedef struct nuclide {
char name[MAXLEN];
double halflife;
} Nuclide;
has exactly the same form as the combined struction definition above, with the word "typedef" before it. This is a general rule: we may take any valid variable declaration and put the word "typedef" in front of it. When we do this we are not declaring a new variable but a new alias. Examples
| ||||||||||||||||||||||||||||