Defining array types in C

Scott Wilson swilson%thetone at Sun.COM
Fri Aug 5 08:24:39 AEST 1988


>I would like to define array types in C so that I can declare variables of
>those types. The first idea that comes to mind is to use a typedef, yet the 
>syntax of typedef (and C declarations for that matter) seems to prohibit this.

This should do what you want, I think:

	typedef char name_type[20];

	typedef struct person {
		name_type name;
		int age;
	} person;

	main()
	{
		person p;

		strcpy(p.name, "Joe Schmoe");
		p.age = 12;
	}

It sounds like you are a Pascal person who is new to C.  The switching
of types and variable names confused me for a long time especially when
typedefing structs.  Often you will see people just use a struct template
without actually defining any variables, and this is also confusing.


--
Scott Wilson		arpa: swilson at sun.com
Sun Microsystems	uucp: ...!sun!swilson
Mt. View, CA



More information about the Comp.lang.c mailing list