473,324 Members | 2,196 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,324 software developers and data experts.

How to undef a typedef??

Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???

Nov 16 '06 #1
15 29484
in************@gmail.com wrote:
Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
To a good first approximation [1], you can't.

Perhaps you could explain why you've painted yourself into this
corner? We can then discuss the alternatives to paint.

[1] No nested scopes.

--
Chris "hantwig efferko VOOM!" Dollin
"Never ask that question!" Ambassador Kosh, /Babylon 5/

Nov 16 '06 #2
in************@gmail.com wrote:
Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
Suggestion #1: Don't.

Suggestion #2: Put the two different `Man' uses in different
scopes. For example, use one typedef in function f() and the
other in function g(), and neither at file scope. Or use one at
file scope in source file a.c and the other in source file b.c,
compiled separately.

--
Eric Sosman
esosman@acm
Nov 16 '06 #3
in************@gmail.com wrote:
Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
You can't use

#undef <identifier>

because the specified <identifierhas to be a macro name, else the
undef will be ignored. However, this works:

#include <stdio.h>
#include <limits.h>

void typedef_func1(void)
{
typedef int Man;
Man i;

i = INT_MAX;

printf("INT_MAX: %d\n", i);
}

void typedef_func2(void)
{
typedef char Man;
Man c;

c = CHAR_MAX;

printf("CHAR_MAX: %d\n", (int)c);
}

int main(void)
{
typedef_func1();
typedef_func2();

return 0;
}

--
Tor <torust AT online DOT no>

Nov 16 '06 #4
in************@gmail.com wrote:
>
Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
As others have already said, "you can't" and "why would you want to?"

However, you can get close with something like:

typedef whatever Man_t1;
typedef something_else Man_t2;

#define Man Man_t1
...
#undef Man
#define Man Man_t2

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 16 '06 #5
"Kenneth Brody" writes:
>Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???

As others have already said, "you can't" and "why would you want to?"
Perhaps there is more than one programmer involved?
Nov 16 '06 #6
osmium wrote:
"Kenneth Brody" writes:
Please don't snip the attributions for things you are still quoting.
Kenneth definitely did *not* write the original question. I've
reinstated the attribution for the OPs question.
>>in************@gmail.com wrote:
>>Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
As others have already said, "you can't" and "why would you want to?"

Perhaps there is more than one programmer involved?
That would be an excellent reason to NOT do it. As others have
suggested, what the OP is trying to do is a very bad idea.
--
Flash Gordon
Nov 16 '06 #7
"Flash Gordon" <sp**@flash-gordon.me.ukwrote in message
news:h1************@news.flash-gordon.me.uk...
osmium wrote:
>"Kenneth Brody" writes:

Please don't snip the attributions for things you are still quoting.
Kenneth definitely did *not* write the original question. I've reinstated
the attribution for the OPs question.
>in************@gmail.com wrote:
>>>Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
As others have already said, "you can't" and "why would you want to?"

Perhaps there is more than one programmer involved?

That would be an excellent reason to NOT do it. As others have suggested,
what the OP is trying to do is a very bad idea.
--
Flash Gordon
Sorry, I thought must of the people on here could count angle brackets and
figure out who is being responded to.

Hint: One angle bracket is smaller than two angle brackets, therefore the
response was directed at Kenneth Brody. I am not the least bit interested
as to who *he* responded to. I guess I read "why would you want to" as
"why would you need to" or "how did you get in this predicament". I agree
it is a bad idea and tried not to comment on the advisability of doing that.
The OP had already been told several times not to do it and that he can't.
I tried to respond to what I saw as the "new" thing in the thread.
Nov 16 '06 #8

Eric Sosman wrote:
in************@gmail.com wrote:
Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
How on Earth did you wind up in that situation?
But how can I do this???

Suggestion #1: Don't.

Suggestion #2: Put the two different `Man' uses in different
scopes. For example, use one typedef in function f() and the
other in function g(), and neither at file scope. Or use one at
file scope in source file a.c and the other in source file b.c,
compiled separately.
Which is still going to be a disaster in its own way. Using the same
name to refer to different types is going to cause problems somewhere
down the line.

It may be time to take a step back and rethink the program's design.

Nov 16 '06 #9
2006-11-16 <4s************@mid.individual.net>,
osmium wrote:
Hint: One angle bracket is smaller than two angle brackets, therefore the
response was directed at Kenneth Brody. I am not the least bit interested
as to who *he* responded to.
You're still supposed to have exactly as many attribution lines as you
have quote levels. Not more, not less.
Nov 16 '06 #10
John Bode wrote:
Eric Sosman wrote:
in************@gmail.com wrote:
Hi,
I did
typedef int Man;
>
After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;

How on Earth did you wind up in that situation?
But how can I do this???
Suggestion #1: Don't.

Suggestion #2: Put the two different `Man' uses in different
scopes. For example, use one typedef in function f() and the
other in function g(), and neither at file scope. Or use one at
file scope in source file a.c and the other in source file b.c,
compiled separately.

Which is still going to be a disaster in its own way. Using the same
name to refer to different types is going to cause problems somewhere
down the line.
Yes, but possibly because of C's limitations.
It may be time to take a step back and rethink the program's design.
Or step over to C++. [cf size_t (et al) in the STL.]

--
Peter

Nov 16 '06 #11

"Tor Rustad дµÀ£º
"
in************@gmail.com wrote:
Hi,
I did
typedef int Man;

After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???

You can't use

#undef <identifier>

because the specified <identifierhas to be a macro name, else the
undef will be ignored. However, this works:

#include <stdio.h>
#include <limits.h>

void typedef_func1(void)
{
typedef int Man;
Man i;

i = INT_MAX;

printf("INT_MAX: %d\n", i);
}

void typedef_func2(void)
{
typedef char Man;
Man c;

c = CHAR_MAX;

printf("CHAR_MAX: %d\n", (int)c);
}

int main(void)
{
typedef_func1();
typedef_func2();

return 0;
}

--
Tor <torust AT online DOT no>

#include <stdio.h>
#include <limits.h>

typedef int Man;

void typedef_func1(void)
{
Man i;
i = INT_MAX;
printf("INT_MAX: %d\n", i);
}

#ifdef Man
#undef Man
typedef char Man;
#endif

void typedef_func2(void)
{
Man c;
c = CHAR_MAX;
printf("CHAR_MAX: %d\n", (int)c);
}
int main(void)
{
typedef_func1();
typedef_func2();

return 0;
}

Nov 17 '06 #12
On 16 Nov 2006 18:41:39 -0800, "wh*****@gmail.com" <wh*****@gmail.com>
wrote in comp.lang.c:
>
"Tor Rustad дµÀ£º
"
in************@gmail.com wrote:
Hi,
I did
typedef int Man;
>
After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
You can't use

#undef <identifier>

because the specified <identifierhas to be a macro name, else the
undef will be ignored. However, this works:

#include <stdio.h>
#include <limits.h>

void typedef_func1(void)
{
typedef int Man;
Man i;

i = INT_MAX;

printf("INT_MAX: %d\n", i);
}

void typedef_func2(void)
{
typedef char Man;
Man c;

c = CHAR_MAX;

printf("CHAR_MAX: %d\n", (int)c);
}

int main(void)
{
typedef_func1();
typedef_func2();

return 0;
}

--
Tor <torust AT online DOT no>


#include <stdio.h>
#include <limits.h>

typedef int Man;

void typedef_func1(void)
{
Man i;
i = INT_MAX;
printf("INT_MAX: %d\n", i);
}

#ifdef Man
#undef Man
typedef char Man;
Did you compile this? What diagnostic did your compiler emit when it
processed the line above.
#endif

void typedef_func2(void)
{
Man c;
c = CHAR_MAX;
printf("CHAR_MAX: %d\n", (int)c);
}
int main(void)
{
typedef_func1();
typedef_func2();

return 0;
}
Absolutely, positively, for sure you did not compile this with a C
compiler.

Either you did not compile it at all, or you compiled it with
something that does not claim to be a C compiler.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 17 '06 #13
wh*****@gmail.com wrote:
"Tor Rustad дµÀ£º
"
in************@gmail.com wrote:
Hi,
I did
typedef int Man;
>
After some code I get a necessity to use the same name Man for char. I
mean to say,I need to
typedef char Man;
But how can I do this???
You can't use

#undef <identifier>

because the specified <identifierhas to be a macro name, else the
undef will be ignored. However, this works:
<snip>
#include <stdio.h>
#include <limits.h>

typedef int Man;

void typedef_func1(void)
{
Man i;
i = INT_MAX;
printf("INT_MAX: %d\n", i);
}

#ifdef Man
#undef Man
typedef char Man;
#endif
This shouldn't work on a conforming C compiler. Preprocessing is done
before compilation proper, thus in the above code, Man should always be
undefined.
void typedef_func2(void)
{
Man c;
c = CHAR_MAX;
printf("CHAR_MAX: %d\n", (int)c);
}
int main(void)
{
typedef_func1();
typedef_func2();

return 0;
}
Nov 17 '06 #14
Jack Klein wrote:
>
On 16 Nov 2006 18:41:39 -0800, "wh*****@gmail.com" <wh*****@gmail.com>
wrote in comp.lang.c:
[...]
#include <stdio.h>
#include <limits.h>

typedef int Man;

void typedef_func1(void)
{
Man i;
i = INT_MAX;
printf("INT_MAX: %d\n", i);
}

#ifdef Man
#undef Man
typedef char Man;

Did you compile this? What diagnostic did your compiler emit when it
processed the line above.
Actually, no diagnostic is required, since "#ifdef Man" is false.
#endif

void typedef_func2(void)
{
Man c;
c = CHAR_MAX;
printf("CHAR_MAX: %d\n", (int)c);
}
int main(void)
{
typedef_func1();
typedef_func2();

return 0;
}

Absolutely, positively, for sure you did not compile this with a C
compiler.

Either you did not compile it at all, or you compiled it with
something that does not claim to be a C compiler.
It should "work" just fine. However, what it does is not what
whua113 thinks it does. Because the "#ifdef Man" is false, the
supposed redefinition of Man never takes place. Man is still a
typedef for int. Since an int can contain CHAR_MAX, the output
"looks right".

Change the printfs to:

printf("INT_MAX: %d, sizeof(Man) is %d\n", (int)c,(int)sizeof(Man));
and
printf("CHAR_MAX: %d, sizeof(Man) is %d\n", (int)c,(int)sizeof(Man));

and you will see that sizeof(Man) is the same in both. (On my
system, they are both 4. Since sizeof char is defined as "1",
you know that Man cannot be a typedef of char.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Nov 18 '06 #15
santosh wrote:
>
wh*****@gmail.com wrote:
[...]
#ifdef Man
#undef Man
typedef char Man;
#endif

This shouldn't work on a conforming C compiler. Preprocessing is done
before compilation proper, thus in the above code, Man should always be
undefined.
[...]

I guess it depends on your definition of "works". It "works" in the
sense that it is a valid, conforming C program. It doesn't "work"
in the sense that the typedef is not done, as the ifdef is false.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 18 '06 #16

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

Similar topics

0
by: Vikas Yadav | last post by:
hi, I have been using a micro$oft mdb with adodb in win32 perl. the problem lately discovred is not ready to get solved. i need to check duplicate and i do a count(*) before insert. what...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
3
by: Sachin | last post by:
hi, Can i use #undef for undefining a function definition and use my function instead? like described below #undef somefunction1 #define somefunction1(a,b) myfunction1(a,b)
6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
2
by: Old Wolf | last post by:
Is this program alright? #include <stdio.h> #undef EOF int EOF(void) { return 0; } int main(void) { return EOF(); }
3
by: johnperl | last post by:
Hi, I have a question about the perl 'undef' function. I am using it to read all line at once in once string. In the same script i am using sftp to transfer the file created by the script which...
0
by: myheartinamerica | last post by:
Hello, I was working on a piece of code where a vendor's #define was causing compiler warnings, which led me to try and do the following: #if defined(VAR1) #define VAR1_SAVE VAR1 #undef VAR1...
2
by: rasmidas | last post by:
Hi, I am new to Perl and could not understand the below line from an existing Perl Code. undef $/; Could anyone please let me know, what does it do? Thanks in advance. Regards...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.