473,224 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Fooling C Compiler

Hi,

Is there a possibility to fool the C compiler into believing that two
data types are different by renaming one of them.
I tried using typedef. But it did not work out. :(:( . C compiler was
clever.
Is there any other way ?

Thx in advans,
Karthik Balaguru

Sep 3 '07 #1
4 1453
karthikbalaguru wrote:
Is there a possibility to fool the C compiler into believing that two
data types are different by renaming one of them.
I tried using typedef. But it did not work out. :(:( . C compiler was
clever.
Is there any other way ?
The better question is: why do you want to do this? Because answering
that will help us suggest alternatives.

--
Suspecting Abstract Types Hedgehog
Otherface: Jena RDF/Owl toolkit http://jena.sourceforge.net/

Sep 3 '07 #2
karthikbalaguru wrote:
Hi,

Is there a possibility to fool the C compiler into believing that two
data types are different by renaming one of them.
I tried using typedef. But it did not work out. :(:( . C compiler was
clever.
Is there any other way ?
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?

"If you lie to the compiler, it will get its revenge."
-- Henry Spencer
--
Eric Sosman
es*****@ieee-dot-org.invalid
Sep 3 '07 #3
karthikbalaguru wrote:
Hi,

Is there a possibility to fool the C compiler into believing that two
data types are different by renaming one of them.
I tried using typedef. But it did not work out. :(:( . C compiler was
clever.
Is there any other way ?

Thx in advans,
Karthik Balaguru
Can you tell us what exactly you want to achieve ? Perhaps, struct or union
might be helpful.

Tejas Kokje
Sep 3 '07 #4
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
karthikbalaguru wrote:
>Is there a possibility to fool the C compiler into believing that two
data types are different by renaming one of them.
I tried using typedef. But it did not work out. :(:( . C compiler was
clever.
Is there any other way ?

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 */

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
7
by: Tao Wang | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I saw cuj's conformance roundup, but the result is quite old. I think many people like me want to know newer c++ standard conformance test...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.