473,382 Members | 1,628 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,382 software developers and data experts.

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 25355
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Fao | last post by:
Hi, I am in my first year of C++ in college and my professor wants me to Write a Program with multiple functions,to input two sets of user-defined data types: One type named 'Sign' declared by...
1
by: Thomas Barnet-Lamb | last post by:
I was wondering if anyone could give me some help with the following. Consider the code snippet: struct qqq{typedef qqq* pointer;}; template<class al> struct foo : public al { template...
0
by: Gary | last post by:
Hi, there, I am going to use a command line parser class, which works well in VC6.0, in VC++7.1. However error message such as "C2059: syntax error :')'", and "C2061: syntax error : identifier...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
7
by: for.fun | last post by:
Hi everybody, I have the following problem : B class need A::MyEnum type and A class need B::MyEnum type. In both case, the class type is incomplete so it is obvious that the ::MyEnum can not...
8
by: Mohammad Omer Nasir | last post by:
Hi, i made a structure in header file "commonstructs.h" is: typedef struct A { int i; A( ) {
8
by: cman | last post by:
What does this kind of typedef accomplish? typedef struct { unsigned long pte_low; } pte_t; typedef struct { unsigned long pgd; } pgd_t; typedef struct { unsigned long pgprot; } pgprot_t I am...
4
by: msukumarbabu | last post by:
Hi all, What will be difference between "typedef enum" and "enum". or difference between “typedef structure" and "structure" I am going through some code. in that some place they are using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.