Eric Sosman said:
Perhaps. Is there a possibility to fool your doctor
so your illness goes undetected and untreated? Is there
a possibility to fool the tax collector so he forgets you
have already paid and allows you to pay twice? Is there
a possibility to fool the Fire Department so their trucks
will go to a different address when your house burns?
That's a bit unfair. I assume "fooling the compiler" was meant to be
facetious.
It reasonable, given the name, to assume that a "typedef" defines a
new and distinct type, rather than just an alias for an existing type.
It's also reasonable to want to create a new and distinct type, so
that the compiler will warn you about any attempt to mix the new type
with the type on which it's based. I think that's what the OP is
trying to do, but he's just discovered that 'typedef' isn't the way to
do it.
Some languages let you do this easily. For example, Ada's
type My_Integer is new Integer;
creates a new type called My_Integer. It has the same characteristics
as Integer, but, for example, attempting to assign an Integer value to
a My_Integer object, or vice versa, is illegal.
C doesn't have such a facility, at least not directly. But like
anything else, you can do it indirectly.
The simplest way to create a new and disinct type is to wrap an
existing type in a structure:
struct my_int {
int i;
};
int x;
my_int y;
/* ... */
x = y; /* ILLEGAL */
x = y.i; /* ok */