typedef a matrix

Q

QQ

Hello

I am reading a program like

typedef BYTE M[5]

What does it mean?

I know if I typedef int a;

I can use a as int

but how about typedef BYTE M[5]?

Thanks a lot!
 
B

baumann@pan

you can use M as a type, which occupies five-byte length memory space.
while int occupies four-byte length memory space for 32bits platform.
 
B

Barry Schwarz

Hello

I am reading a program like

typedef BYTE M[5]

What does it mean?

I know if I typedef int a;

I can use a as int

but how about typedef BYTE M[5]?

Thanks a lot!

M is now a synonym for the type "array of 5 BYTE".

M x;
would be identical to
BYTE x[5];


<<Remove the del for email>>
 
O

osmium

baumann@pan said:
you can use M as a type, which occupies five-byte length memory space.
while int occupies four-byte length memory space for 32bits platform.

A reasonable guess, but that would only be true if there is code elsewhere
in the program that defines BYTE as a char of some sort. Neither BYTE or
byte are primitive types in the C language.
 
K

Keith Thompson

QQ said:
I am reading a program like

typedef BYTE M[5]

What does it mean?

Very likely, it means that the author is being foolish.

Using a typedef for an array type hides the fact that it's an array.
Since arrays are used differently from other types (e.g., an array
name is converted to a pointer in most contexts), this is usually a
bad idea.
 
B

baumann@pan

osmium said:
A reasonable guess, but that would only be true if there is code elsewhere
in the program that defines BYTE as a char of some sort. Neither BYTE or
byte are primitive types in the C language.


you are right, i have ignored the fact that BYTE is not primitive type
of c/c++.

so what i said above is not exactly.
 
A

Ari Lukumies

Keith said:
QQ said:
typedef BYTE M[5]

What does it mean?

Using a typedef for an array type hides the fact that it's an array.
Since arrays are used differently from other types (e.g., an array
name is converted to a pointer in most contexts), this is usually a
bad idea.

However, it makes a program easier to write, in many cases such as the
type is expected as a parameter to a function, for example (not that
I'd recommend it, though).

-atl-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top