Can You Type Alias an Existing User-Defined Type in C?
Say I Want to Define Two Structs, the First One Has a Type, and the Other I Want to Be of the Same Type as the First. Is This Possible in C99? Example: Typedef...
Say I want to define two structs, the first one has a type, and the other I want to be of the same type as the first. Is this possible in C99?
Example:
typedef struct {
fieldA;
fieldB;
} typeA;
struct B {
fieldA
fieldB
};
typedef B A;
If not typedef, is there another keyword/way to do this?
Edit: It seems I wasn't being as clear as possible, judging from the feedback so far (which I greatly appreciate!)
My specific scenario is a typedef struct definition that is required to type alias another struct.
1 Answer
Yes of course! It's just like:
#include <stdio.h>
typedef int value_t;
typedef value_t data_t;
int main()
{
data_t i = 1;
printf("%d\n", i);
return 0;
}
You can typedef as many times as you like.