如何取消一个typedef? [英] How to undef a typedef??

查看:927
本文介绍了如何取消一个typedef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我做了

typedef int Man;


经过一些代码我有必要使用相同的名为Man for char。我想b $ b意思是说,我需要

typedef char Man;

但我怎么能这样做呢?

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???

推荐答案

*** *********@gmail.com 写道:
in************@gmail.com wrote:



我做了

typedef int Man;


在一些代码之后,我有必要使用相同名称Man for char。我想b $ b意思是说,我需要

typedef char Man;

但我怎么能这样做?
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???



为了得到良好的初步[1],你不能。


也许你可以解释为什么你'自己画了这个

角落?然后我们可以讨论油漆的替代品。


[1]没有嵌套的范围。


-

克里斯hantwig efferko VOOM! Dollin

永远不要问这个问题! Kosh大使,/ Babylon 5 /

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/


在************ @ gmail.com 上写道:
in************@gmail.com wrote:



我做了

typedef int Man;


经过一些代码后,我有必要使用相同名称Man for char。我想b $ b意思是说,我需要

typedef char Man;

但我怎么能这样做?
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???



建议#1:不要。


建议#2:把两个不同的男人使用在不同的

范围内。例如,在函数f()中使用一个typedef,在函数g()中使用

,在文件范围内都不使用。或者在源文件ac中使用

文件范围,在源文件中使用另一个bc,

单独编译。


- -

Eric Sosman

esosman @ acm

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


在************ @ gmail.com 写道:



我做了

typedef int Man;


经过一些代码我有必要使用相同的名字男人为char。我想b $ b意思是说,我需要

typedef char Man;

但我怎么能这样做?
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???



你不能使用


#undef< identifier>


因为指定的< identifier必须是宏名称,否则

undef将被忽略。但是,这有效:


#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(无效)

{

typedef_func1();

typedef_func2();


返回0;

}


-

Tor< torust AT在线DOT否> ;

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>


这篇关于如何取消一个typedef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆