469,129 Members | 1,720 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,129 developers. It's quick & easy.

How to remove the type defined by "typedef"?thx

Hi:
In some code , I used typedef unsigned char BOOL; /*boolean */

But in other code , I must use typedef unsigned int BOOL; /* boolean
*/

How to remove the previous typedef ?
Hercules

Nov 13 '05 #1
6 23868
"hercules" <we*****@harbournetworks.com> writes:
In some code , I used typedef unsigned char BOOL; /*boolean */

But in other code , I must use typedef unsigned int BOOL; /* boolean
*/

How to remove the previous typedef ?


This cannot be done. However, you can use
#define BOOL unsigned char
instead of the initial typedef, then write
#undef BOOL
#define BOOL unsigned int
later to change it. Not elegant, but it should work.
--
"Given that computing power increases exponentially with time,
algorithms with exponential or better O-notations
are actually linear with a large constant."
--Mike Lee
Nov 13 '05 #2

"hercules" <we*****@harbournetworks.com> wrote in message
news:bq**********@news.yaako.com...
Hi:
In some code , I used typedef unsigned char BOOL; /*boolean */

But in other code , I must use typedef unsigned int BOOL; /* boolean
*/

How to remove the previous typedef ?


You really can't remove or redefine a typedef[1]. About the best you can do
is patch around it with the CPP:

typedef unsigned char BOOL;
/* Some code here */

#define BOOL anotherBOOLtype
typedef unsigned int BOOL;

BTW: if it is all your code, why do you have to have the two distinct
definitions? Or, are you doing something like including two different
header files with the above definitions?

[1] Unless, of course, it was defined within a block. In that case, ending
the block will end the scope of the typedef, effectively removing it. I
rather doubt this applies to your code -- I just add this to make my
statement technically correct.

--
poncho

Nov 13 '05 #3
On Mon, 1 Dec 2003 12:03:03 +0800, in comp.lang.c , "hercules"
<we*****@harbournetworks.com> wrote:
Hi:
In some code , I used typedef unsigned char BOOL; /*boolean */

But in other code , I must use typedef unsigned int BOOL; /* boolean
*/

How to remove the previous typedef ?


You can't: Instead, fix your code. Two different defnitions of the
same type name is an accident waiting to happen.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #4
You cannot undefine a type. If it is possible to change the
typedefs to #defines, you could use #undef to define the old
one.

However, I would not recommend it. It is probably better to make
code changes so that you do not have to live with these confusing
declarations.

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Distributed System Design CASE Tool
Nov 13 '05 #5
In <bq**********@news.yaako.com> "hercules" <we*****@harbournetworks.com> writes:
In some code , I used typedef unsigned char BOOL; /*boolean */

But in other code , I must use typedef unsigned int BOOL; /* boolean
*/

How to remove the previous typedef ?


The only legitimate situation where this can happen is when using two
libraries, each of them coming with its own definition of BOOL.

The right thing in such a case is to use different identifiers:

/* The typedef's must only be provided if the library headers */
/* expect BOOL to be already defined, instead of defining it */
/* themselves. */

typedef unsigned char lib1BOOL;
typedef unsigned int lib2BOOL;

#define BOOL lib1BOOL
#include <lib1.h>

#define BOOL lib2BOOL
#include <lib2.h>

#undef BOOL

/* use lib1BOOL and lib2BOOL in your own declarations */

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #6
In message <bq**********@sunnews.cern.ch>
Da*****@cern.ch (Dan Pop) wrote:
The only legitimate situation where this can happen is when using two
libraries, each of them coming with its own definition of BOOL.

The right thing in such a case is to use different identifiers:

/* The typedef's must only be provided if the library headers */
/* expect BOOL to be already defined, instead of defining it */
/* themselves. */

typedef unsigned char lib1BOOL;
typedef unsigned int lib2BOOL;

#define BOOL lib1BOOL
#include <lib1.h>
#undef BOOL

is required here; one is not allowed to redefine a currently-defined
identifier with a different definition.
#define BOOL lib2BOOL
#include <lib2.h>

#undef BOOL

/* use lib1BOOL and lib2BOOL in your own declarations */


--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Fao | last post: by
1 post views Thread by Thomas Barnet-Lamb | last post: by
reply views Thread by Gary | last post: by
134 posts views Thread by jacob navia | last post: by
8 posts views Thread by Mohammad Omer Nasir | last post: by
8 posts views Thread by cman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.