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??? | | | | re: How to undef a typedef?? informativeguy@gmail.com wrote: Quote:
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/ | | | | re: How to undef a typedef?? informativeguy@gmail.com wrote: Quote:
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 | | | | re: How to undef a typedef?? informativeguy@gmail.com wrote: Quote:
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> | | | | re: How to undef a typedef?? informativeguy@gmail.com wrote: Quote:
>
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:ThisIsASpamTrap@gmail.com> | | | | re: How to undef a typedef??
"Kenneth Brody" writes: Quote: Quote:
>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? | | | | re: How to undef a typedef??
osmium wrote: Quote:
"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. Quote: Quote:
>>informativeguy@gmail.com wrote:
> Quote: Quote:
>>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 | | | | re: How to undef a typedef??
"Flash Gordon" <spam@flash-gordon.me.ukwrote in message
news:h1ku24x5ta.ln2@news.flash-gordon.me.uk... Quote:
osmium wrote: Quote:
>"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.
> Quote: Quote:
>informativeguy@gmail.com wrote:
>> Quote:
>>>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. | | | | re: How to undef a typedef??
Eric Sosman wrote: Quote: informativeguy@gmail.com wrote:
> Quote:
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? Quote: Quote:
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. | | | | re: How to undef a typedef??
2006-11-16 <4s3r2gFtn2uaU1@mid.individual.net>,
osmium wrote: Quote:
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. | | | | re: How to undef a typedef??
John Bode wrote: Quote:
Eric Sosman wrote: Quote: informativeguy@gmail.com wrote: Quote:
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?
> Quote: Quote:
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. Quote:
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 | | | | re: How to undef a typedef??
"Tor Rustad дµÀ£º
" Quote: informativeguy@gmail.com wrote: Quote:
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;
} | | | | re: How to undef a typedef??
On 16 Nov 2006 18:41:39 -0800, "whua113@gmail.com" <whua113@gmail.com>
wrote in comp.lang.c: Quote:
>
"Tor Rustad дµÀ£º
" Quote: informativeguy@gmail.com wrote: Quote:
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. Quote:
#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 | | | | re: How to undef a typedef?? whua113@gmail.com wrote: Quote:
"Tor Rustad дµÀ£º
" Quote: informativeguy@gmail.com wrote: Quote:
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> Quote:
#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. Quote:
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;
}
| | | | re: How to undef a typedef??
Jack Klein wrote: Quote:
>
On 16 Nov 2006 18:41:39 -0800, "whua113@gmail.com" <whua113@gmail.com>
wrote in comp.lang.c:
[...] Quote: Quote:
#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. Quote: Quote:
#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:ThisIsASpamTrap@gmail.com> | | | | re: How to undef a typedef??
santosh wrote: [...] Quote: Quote:
#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:ThisIsASpamTrap@gmail.com> |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|