C/C++ and Fortran

 View Only

typedef redeclaration in C11

By Archive User posted Thu December 18, 2014 01:41 AM

  

Originally posted by: FangLu



You can use the typedef declaration to define your own identifiers that can be used in place of type specifiers, such as int, float, and double. With the typedef redeclaration feature, you can redefine a name that is a previous typedef name in the same scope to refer to the same type. For example:

typedef char MyChar;
typedef char MyChar;

In this example, both statements contain typedef declarations for the name MyChar.

 

Such redeclaration is valid only if both declarations refer to the same type, which is char in this example. However, if two declarations refer to different types as in the following example:

typedef char MyChar;
typedef int MyChar;
 

The following error messages will be issued because a typedef cannot redefine a name that was previously declared as a different type:

2:13: error: conflicting declaration 'typedef int MyChar'
1:14: error: 'MyChar' has a previous declaration as 'typedef char MyChar'
0 comments
0 views

Permalink