Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this typedef statement mean?

Tags:

c++

typedef

In a C++ reference page they provide some typedef examples and I'm trying to understand what they mean.

// simple typedef typedef unsigned long mylong;   // more complicated typedef typedef int int_t, *intp_t, (&fp)(int, mylong), arr_t[10]; 

So the simple typedef (the first declaration) I understand.

But what are they declaring with the second one (repeated below)?

typedef int int_t, *intp_t, (&fp)(int, ulong), arr_t[10]; 

Particularly what does (&fp)(int, mylong) mean?

like image 345
rsgmon Avatar asked Feb 27 '14 07:02

rsgmon


People also ask

What does typedef mean?

A typedef declaration lets you define your own identifiers that can be used in place of type specifiers such as int , float , and double . A typedef declaration does not reserve storage.

What is typedef example?

typedef is used to define new data type names to make a program more readable to the programmer. For example: | main() | main() { | { int money; | typedef int Pounds; money = 2; | Pounds money = 2 } | } These examples are EXACTLY the same to the compiler.

What is typedef declaration in C?

A typedef declaration is a declaration with typedef as the storage class. The declarator becomes a new type. You can use typedef declarations to construct shorter or more meaningful names for types already defined by C or for types that you have declared.

How do we use typedef in C?

The typedef is a keyword used in C programming to provide some meaningful names to the already existing variable in the C program. It behaves similarly as we define the alias for the commands. In short, we can say that this keyword is used to redefine the name of an already existing variable.


1 Answers

It's declaring several typedefs at once, just as you can declare several variables at once. They are all types based on int, but some are modified into compound types.

Let's break it into separate declarations:

typedef int int_t;              // simple int typedef int *intp_t;            // pointer to int typedef int (&fp)(int, ulong);  // reference to function returning int typedef int arr_t[10];          // array of 10 ints 
like image 111
Mike Seymour Avatar answered Oct 02 '22 10:10

Mike Seymour