Regarding typedef

O

Oskars Salnins

Hi
What does the statement:

typedef unsigned my_type_name;

mean? Cannot find an answer to this in ordinary books on C.
 
L

lndresnick

Oskars said:
Hi
What does the statement:

typedef unsigned my_type_name;

mean? Cannot find an answer to this in ordinary books on C.

It creates a new name for the unsigned int data type. You could then
use
it in place of a type, e.g.
my_type_name i = 0;

is the now the same as
unsigned i = 0;
or
unsigned int i = 0;

I assume you were confused by the fact that "int" to be inferred? That
is a bit odd, but that is how it works. You can likewise say "signed
short" meaning
"signed short int".

-David
 
M

Martin Ambuhl

Oskars said:
Hi
What does the statement:

typedef unsigned my_type_name;

mean? Cannot find an answer to this in ordinary books on C.

It means that 'my_type_name' is now a synonym for 'unsigned int'.
'unsigned' here is short for 'unsigned int'.
 
A

Angrez Singh

Hi,

It means that you have given a new name to old unsigned data type.
So you can use it instead of unsigned.

For e.g.:
typedef unsigned my_unsigned;

my_unsigned x = 0;

now x will be of type unsigned.

Regards,
Angrez
 
V

vijoeyz

Angrez said:
Hi,

It means that you have given a new name to old unsigned data type.
So you can use it instead of unsigned.

For e.g.:
typedef unsigned my_unsigned;

my_unsigned x = 0;

now x will be of type unsigned.

Regards,
Angrez

Yes.

typedef is an useful construct that the language provides. For
example,
just to explain the typedef, Symbian OS C++ provides generic data
types:

"TInt32, TInt16 and TInt8 map onto C++ built-in types in most
implementations.
These types should only be used where the size of the integer is of
first
importance."


Here, the type definition could take the following form:

typedef int TInt32;
typedef short TInt16;
typedef char TInt8;

Using typedef's in such manner provides an easy inference, ease of
portability,
etc.


Kind regards,
 

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
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top