Syntax explanation

In code:

struct tagPaint
{
}Paint,//<<<--------------what's this (Paint)?
*pPaint;//<<<-------------and this(*pPaint)?

I mean do I declare variable with name Paint of type tagPaint and pointer called pPaint to tagPaint?
Thanks.

Upvotes: 0

Views: 204

Answers (6)

anon
anon

Reputation:

Paint is a variable of type tagPaint. pPaint is a pointer to type tagPaint. If you want them to define types, then you need:

typedef struct tagPaint {
   ...
}  Paint, * pPaint;

but this is C usage - you should not be writing code like that in C++. and even in C, defining a type that hides the fact that something is a pointer is considered bad style.

Upvotes: 2

McAden
McAden

Reputation: 13972

You're declaring both of them. You can declare primitives the same way:

int a, b, c, d;

But instead of the int type you're declaring an instance of tagPaint along with a pointer to a tagPaint.

Upvotes: 0

James Morris
James Morris

Reputation: 4935

Paint is an instance of struct tagPaint, and pPaint is a pointer to struct tagPaint.

The structure needs the typedef keyword preceding it in order to use Paint as a type, and pPaint as a pointer to type Paint.

Upvotes: 1

CB Bailey
CB Bailey

Reputation: 791451

Yes, in the code that you've actually posted Paint is declared as a struct tagPaint and pPaint is a pointer to a struct tagPaint.

Are you sure you haven't missed a typedef from before struct? Given the names, defining typedefs would be far more usual.

Upvotes: 1

Potatoswatter
Potatoswatter

Reputation: 137770

You are allowed to declare and define a struct or class in a declaration of a variable of that type.

So, that declaration defines three symbols: tagPaint (which can also be called struct tagPaint in C style), Paint which is a tagPaint, and pPaint which points to a tagPaint.

Upvotes: 5

Alex F
Alex F

Reputation: 43311

You declare both of them :)

Upvotes: 0

Related Questions