Chinaunix

标题: 请问gcc如果编译过如下代码?谢谢 [打印本页]

作者: hiei1321    时间: 2007-10-11 09:59
标题: 请问gcc如果编译过如下代码?谢谢
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#ifndef DOUBLE
//#define DOUBLE double

typedef double DOUBLE;
#endif

#ifndef DOUBLE
//#undef DOUBLE

//#define DOUBLE double

typedef double DOUBLE;
#endif

main()
{
        char lpszNewWorld[] = "hello the new unix programmers' world\n";
}

作者: hiei1321    时间: 2007-10-11 10:07
gcc对于ifndef下typedef的处理好像分开了。
作者: hiei1321    时间: 2007-10-11 10:12
........................
........................
........................
# 962 "/usr/include/stdlib.h" 3 4
extern int getloadavg (double __loadavg[], int __nelem)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
# 978 "/usr/include/stdlib.h" 3 4

# 4 "temp.c" 2



typedef double DOUBLE;





typedef double DOUBLE;


main()
{
char lpszNewWorld[] = "hello the new unix programmers' world\n";
}

作者: hiei1321    时间: 2007-10-11 11:08
大家帮帮忙吧,进来说句话也好,我这一直F5   好无聊啊。
作者: flw2    时间: 2007-10-11 11:23
#ifndef XXX
int XXX = 1;
#endif

#ifndef XXX
int XXX = 1;
#endif
作者: while(1)    时间: 2007-10-11 11:27
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#ifndef DOUBLE
#define DOUBLE
typedef double DOUBLE;
#endif
#ifndef DOUBLE
typedef double DOUBLE;
#endif

main()
{
        char lpszNewWorld[] = "hello the new unix programmers' world\n";
}


作者: hiei1321    时间: 2007-10-11 12:36
问题是这样的,我们在移植vxworks下的代码,同样都是gcc编译器,为什么我这里编译不过去?修改代码是最后的一招,有没有方法在gcc编译的搞定它?
作者: hiei1321    时间: 2007-10-11 12:48
实际情况是这样的:
-----------------------------------
///////a.h
#ifndef DOUBLE
typedef double DOUBLE;
#endif
----------------------------------
////////b.h
#ifndef DOUBLE
typedef double DOUBLE;
#endif
----------------------------------
/////////c.c
#include "a.h"
#include "b.h"
----------------------------------
编译c.c的时候就会出错。

大家看看是不是我编译器设置的问题,如果不是,在不修改代码的情况下能否搞定,实在不行我就只能修改代码了。
作者: flw2    时间: 2007-10-11 13:36
别在不同的头文件里typedef就可以了
作者: hiei1321    时间: 2007-10-11 15:40
如果改代码,我就不 发上来了, 帮忙想想办法,谢谢。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2