Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

structure in c dont understanding K&R page no. 129

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,601
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Activity points
10,611
I am learning the c from K&R text book .and stops where the page no .129 where the following code

Code:
[COLOR=#222426][FONT=Arial] struct rect {
[/FONT][/COLOR][COLOR=#222426][FONT=Arial]struct point pt1;[/FONT][/COLOR]
[COLOR=#222426][FONT=Arial]struct point pt2;[/FONT][/COLOR]
[COLOR=#222426][FONT=Arial]};[/FONT][/COLOR]
What it does mean ?
 

Alter way of structure declaration

Code:
typedef struct point ;

struct rect {
  point pt1;
  point pt2;
};
 

Alter way of structure declaration
No legal typedef.

Either write
Code:
struct point{
   int x;
   int y;
};

typedef struct point tpoint;

struct rect {
  tpoint pt1;
  tpoint pt2;
};

Or

Code:
typedef struct {
   int x;
   int y;
} tpoint;

struct rect {
  tpoint pt1;
  tpoint pt2;
};
 
I should also add you might come across the following:

Code:
typedef struct [COLOR="#FF0000"]point[/COLOR]{
   int x;
   int y;
} [COLOR="#0000FF"]tpoint[/COLOR];

Which incorporates both the struct type identifier, point, and the typedef type identifier, tpoint, into a single definition.

Or as most C compilers are case sensitive by default:

Code:
typedef struct [COLOR="#FF0000"]tpoint[/COLOR]{
   int x;
   int y;
} [COLOR="#0000FF"]TPOINT[/COLOR];

Where the struct type identifier is tpoint and the typedef type identifier is TPOINT.


BigDog
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top