473,395 Members | 1,678 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,395 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 1473
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.